Mail Archives: djgpp/1996/12/13/01:09:37
In article <32A91EFF DOT 6C6FD6F0 AT alcyone DOT com>,
Erik Max Francis <max AT alcyone DOT com> 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.
<a href="http://www.cs.indiana.edu/finger/mofo.ssl.berkeley.edu/korpela/w">
Click here for more info.</a>
- Raw text -