2

I've been happily compiling my code with GCC without issue for the past three months until I rebuilt my cross-compiler, which was when I found myself getting the message "error: bit-field '...' with non-integral type".

An example of an offending enum is below:

typedef unsigned char byte;

enum class opStatus : byte
{
    /* Process has yet to begin execution */
    Ready,
    /* Process can resume execution */
    Started,
    /* Process has completed */
    Finished,
    /* Process is handling shutdown */
    Finishing,
};

struct // Example usage
{
    opStatus Status : 2;
};

Why is this happening?

8
  • Maybe you broke your cross-compiler, or forgot to build in C++11 support. Without seeing what you actually did, and without knowing what your compiler is, there's not much else to say here. Commented Nov 6, 2012 at 10:13
  • GNU GCC G++ 4.6.0 using config C++0x. And I've re-built the compiler a number of times using fresh sources. Commented Nov 6, 2012 at 10:28
  • Since this seems to be an issue caused by your cross-compiler, code from that compiler would be usefull to answer this. Commented Nov 6, 2012 at 10:30
  • Note that the code struct { opStatus Status : 2; }; will give compilation error anyway even if opStatus Status : 2 is allowed in the language! You must introduce at least one name in the declaration. So write struct tag_name { opStatus Status : 2; }; or struct { opStatus Status : 2; } object_name;. Commented Nov 6, 2012 at 10:31
  • 2
    Try to come up with a SSCCE. Commented Nov 6, 2012 at 11:04

1 Answer 1

1

Make the bitwidth 8. Its a byte after all.

Once I did that (and added a name for the struct),

g++ -std=c++11 

didn't give me any warning or error.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.