Hi
Is there any method to restrict the enumerated variable in C to occupy only one byte? I am using gcc (GCC) versin 4.0.0...
please comment
thanks
Printable View
Hi
Is there any method to restrict the enumerated variable in C to occupy only one byte? I am using gcc (GCC) versin 4.0.0...
please comment
thanks
I'm pretty sure an enum is supposed to take only as much space as it needs. There is a compiler switch in gcc that tells it to always use int as storage size but that should be off by default.
In general, no there isn't.
In C, enums are just named integers, so that is what their size is. C++ makes a better job of it on the size front.
http://david.tribble.com/text/cdiffs.htm#C99-enum-const
Did you think of doing this?
Quote:
Originally Posted by gcc manual
Would it not be legal to cast it into 1 byte?
Or have I completely missed the point?Code:#include <stdio.h>
enum foo_t {
FOO_TEST=0,
FOO_BAR
};
int main(void)
{
char abc = (char)FOO_TEST;
return 0;
}