Mail Archives: djgpp/1996/02/04/04:45:05
On Fri, 2 Feb 1996, Brad Burgan wrote:
> struct TestStruct
> {
> char var1;
> short var2 __attribute__ ((packed));
> };
>
> int main(void)
> {
> printf("sizeof(TestStruct): %i", sizeof(TestStruct));
> }
> // ===end of file===
>
> Can anyone tell me why this program produces:
>
> sizeof(TestStruct): 4
You called this test.cpp, so I assume you've compiled it as a C++
program. First, you should declare all the struct fileds as packed. But
the *real* bad news is that in GCC 2.7.2 there is a bug in the C++
compiler which makes the packed structs not packed (they work ok in C
programs).
> Info says you can do this:
>
> struct S
> {
> blah
> } __attribute__ ((packed)); // <<<<< line 106
>
> But I get a compiler error that ; is missing on line 106
Did you put a ; after `blah'? If not, that is the error.
You can also use the -fpack-struct option (new with gcc 2.7) to make all
the structs packed.
- Raw text -