delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1995/01/28/15:10:19

Date: Sat, 28 Jan 1995 09:45:59 -0500 (EST)
From: Kimberley Burchett <OKRA AT max DOT tiac DOT net>
Sender: Kimberley Burchett <OKRA AT max DOT tiac DOT net>
Reply-To: Kimberley Burchett <OKRA AT max DOT tiac DOT net>
Subject: RE: Major bug
To: DJGPP Mailing List <djgpp AT sun DOT soe DOT clarkson DOT edu>

On Fri, 27 Jan 1995, John E. Davis wrote:

> >   printf("%d\n", sizeof(header));
> >
> >Which gave me 24 for output.  If you look carefully, however, you will see 
> >that it should be 22.  Why is it giving be 24?  Have no clue, but it must 
> >be a bug.  I actually checked the sizeof() of each field in the header 
> 
> I am afraid that the bug is in *your* program.  You are depending upon the
> non-portable behavior of the structure being packed.  As you have found out,
> gcc pads it.  There might be some compiler switch to force the compiler to
> pack the structure but I would not rely on it.

  The switch goes by the name of "__attribute__ ((packed))".  I define it
to PACK so I can do stuff like this: 

struct {
  char a   PACK;
  short b  PACK;
  char c   PACK;
}
							Kim


- Raw text -


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