www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/12/13/01:09:37

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  <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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019