www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/03/19/15:26:14

Message-Id: <m0w7Lyz-000S2jC@natacha.inti.edu.ar>
Comments: Authenticated sender is <salvador AT natacha DOT inti DOT edu DOT ar>
From: "Salvador Eduardo Tropea (SET)" <salvador AT natacha DOT inti DOT edu DOT ar>
Organization: INTI
To: "Ian Mausolus" <mausolus AT ican DOT net>, djgpp AT delorie DOT com
Date: Wed, 19 Mar 1997 17:18:53 +0000
MIME-Version: 1.0
Subject: Re: packed structures

"Ian Mausolus" <mausolus AT ican DOT net> wrote:

> Can someone please tell me what the following satements do and how to use
> them?  As well, what is the difference between them?
> 
> 1) #pragma pack(...)
> 2) __attribute__((packed))
> 
GCC alignes all the data so the members of an struct are aligned to 32 bits 
boundaries. For example

struct 
{
 char a;
 int b;
} foo;

will use 8 bytes of memory, a will be in the offset 0 and b in the offset 4, 
but if you use the packed attribute b will be at offset 1 (be carreful foo will 
still using 8 bytes).
  Under plain C the attribute is enough but under C++ there are a bug in the 
C++ front-end and you need to enclose the declaration with the above pragma.

SET

--------------- 0 --------------------------------
Salvador Eduardo Tropea (SET).
Address: Curapaligue 2124, Caseros, 3 de Febrero
Buenos Aires, (1678), ARGENTINA
TE: +(541) 759 0013

- Raw text -


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