From: korpela AT islay DOT ssl DOT berkeley DOT edu (Eric J. Korpela) Newsgroups: comp.os.msdos.djgpp Subject: Re: Padding Question Date: 10 Dec 1996 01:30:23 GMT Organization: Cal Berkeley-- Space Sciences Lab Lines: 40 Message-ID: <58ieff$8mn@agate.berkeley.edu> References: <32A810D9 DOT 366E9B4E AT m-net DOT arbornet DOT org> <32A85B15 DOT 4015 AT skygames DOT com> <32A8F16C DOT 596F AT cs DOT com> <32A91EFF DOT 6C6FD6F0 AT alcyone DOT com> NNTP-Posting-Host: islay.ssl.berkeley.edu To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp In article <32A91EFF DOT 6C6FD6F0 AT alcyone DOT com>, Erik Max Francis wrote: > >I'm curious -- what's "unevil" or "unhackish" about using attributes to >pack structures? I can only think of one thing (OK maybe two). 1. Try to use #pragma pack() in a macro. 2. The __attribute__ applies to a specific variable. #pragma applies globally. How does each apply in a typedef? In the following what is the packing of the variables one and two? Is it the same? Should it be? #pragma pack(1) typedef struct { short s; int i; } first; #pragma pack() typedef struct { short s __attribute__((packed)); int i __attribute__((packed)); } second; first one={1,2}; second two={3,4}; (The answer is no, they aren't the same. two has the default alignment overall even though its elements are packed. one appears to have ignored the #pragma pack(1) all together.) Eric -- Eric Korpela | An object at rest can never be korpela AT ssl DOT berkeley DOT edu | stopped. Click here for more info.