I'm writing a cross-platform code and I need to be sure the following won't make me trouble.

struct X
{
   unsigned char a:3;
   unsigned char b:5;
};

Is using other then int types is part of the ANSI C?
Will it be compiled with every compiler?

Is using other then int types is part of the ANSI C?

The behavior is implementation-defined if you use anything other than _Bool, signed int, or unsigned int.

The behavior is implementation-defined if you use anything other than _Bool, signed int, or unsigned int.

Do you mean the behavior of the compiler is implementation defined??
Can you clarify?

I mean anything else is non-portable. The compiler is free to allow or disallow types beyond int (signed or unsigned) and _Bool, but it must document which types are allowed beyond the ones required by the standard.

It may not be guaranteed to be portable by the C standard, but I've never heard of a C compiler that doesn't have signed and unsigned char's.

I'm sure there's some minimalist one that is that way, but it's designed for embedded applications, I'd bet $$$.

Comments
void main is harmless 99.9% of the time, but we don't cut any slack for it.

Thanks for the answers, but maybe my question wasn't clear.
I'm asking specifically regarding bit fields in struct. All the compilers I work with do have signed and unsigned chars in general, but I want to be sure that it's ok to use them in bit fields. Is that what you meant?

Thanks for the answers, but maybe my question wasn't clear.
I'm asking specifically regarding bit fields in struct.

Your question was perfectly clear, and my answer is equally clear. Your bit fields can use _Bool and int (signed or unsigned) as the base type without any portability risk. Anything else is not portable.

Your question was perfectly clear, and my answer is equally clear. Your bit fields can use _Bool and int (signed or unsigned) as the base type without any portability risk. Anything else is not portable.

Thank you!

This question has already been answered. Start a new discussion instead.