Mail Archives: djgpp/1997/08/12/01:09:06
Insomnia wrote:
>
> At least part of your problem is most likely due to gcc's
> behavior of 32-bit alligning fields in a structure.
that is correct but a large part should be because int's are 32 bit
rather than 16.
> struct mystruct {
> char element1 __attribute__ ((packed));
> int element2 __attribute__ ((packed));
> .....
> };
> Hope this helps. Corrections/constructive criticism welcome,
> as are flames
not a flame. in declaring structs as packed, you do not have to apply
the attribute to each element of the struct, you can apply it to the
struct as a whole:
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
typedef struct a
{
short x;
int y;
} a;
struct p
{
short x;
int y;
} __attribute__((packed)) p;
printf("%lu\n", sizeof(a));
printf("%lu\n", sizeof(p));
return 0;
}
output:
D:\djgpp\C>test
8
6
--
Sinan
*******************************************************************
A. Sinan Unur WWWWWW
|--O+O
mailto:sinan DOT unur AT cornell DOT edu C ^
http://www.people.cornell.edu/pages/asu1/ \ ~/
Unsolicited e-mail is _not_ welcome, and will be billed for.
*******************************************************************
- Raw text -