Mail Archives: djgpp/1997/11/14/01:39:58
At 06:40 11/13/1997 GMT, Johan Levin wrote:
>struct test_struct {
> int p1;
> char ch;
> int p2;
>};
>[snipped]
>In this case all elements of the structure becomes
>dword-aligned. That might be good for speed, but
>I'm trying to read the header of a file that doesn't
>align it's fields like this. Is it possible to disable
>this aligning for a structure?
Yes. GCC has a field attribute called `packed'. It's in the Info docs; try:
info "gcc" "c extensions" "variable attributes"
Basically, what you want will look something like this:
struct test_struct {
int p1 __attribute__((packed));
char ch __attribute__((packed));
int p2 __attribute__((packed));
};
HTH
Nate Eldredge
eldredge AT ap DOT net
- Raw text -