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
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?
Originally Posted by gcc manual
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
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; }
Last edited by zacs7; 07-26-2007 at 12:53 AM.