D
Derek
A simple struct
struct Foo {
float x;
char y;
};
The above class occupies 8 bytes on my Win32 system
according to sizeof(Foo). This makes sense because
of the platform's alignment requirements. However,
I can force the struct to be packed by using a non-
standard compiler extension (in my case GCC's "packed"
attribute):
struct Foo {
float x;
char y;
} __attribute__((packed));
Now sizeof(Foo) is 5 bytes. However, when I replace
char y with an enum, say
struct Foo {
float x;
enum { Y } y;
};
the sizeof(Foo) remains 8 whether I pack it or not.
I get the same behavior with MSVC's #pragma pack.
Is an enum always the same size as an int? I thought
an enum was supposed to be as small as needed to hold
all of its values, in this case 1 byte.
struct Foo {
float x;
char y;
};
The above class occupies 8 bytes on my Win32 system
according to sizeof(Foo). This makes sense because
of the platform's alignment requirements. However,
I can force the struct to be packed by using a non-
standard compiler extension (in my case GCC's "packed"
attribute):
struct Foo {
float x;
char y;
} __attribute__((packed));
Now sizeof(Foo) is 5 bytes. However, when I replace
char y with an enum, say
struct Foo {
float x;
enum { Y } y;
};
the sizeof(Foo) remains 8 whether I pack it or not.
I get the same behavior with MSVC's #pragma pack.
Is an enum always the same size as an int? I thought
an enum was supposed to be as small as needed to hold
all of its values, in this case 1 byte.