www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/11/08/16:55:39

From: varlese AT tech DOT ascom DOT ch (Chris Varlese)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Problem with data alignments...
Date: 8 Nov 1996 16:57:22 GMT
Organization: Ascom Hasler AG, Berne, Switzerland
Lines: 26
Message-ID: <55vopi$nkf@ascomax.hasler.ascom.ch>
References: <01bbca0a$0f930e40$a5fd82c1 AT pz43 DOT dial DOT pipex DOT com>
NNTP-Posting-Host: laguna.be.tech.ascom.ch
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

In article <01bbca0a$0f930e40$a5fd82c1 AT pz43 DOT dial DOT pipex DOT com>,
	"~^Fozz^~" <fozz AT dial DOT pipex DOT com> writes:
>if I have a structure of a word then a long word, the first word is
>rounded up to a long word in size for the structure variable....eg..
>struct test {
> short var1;
> long var2;
>};
>here if I do a ... sizeof(struct test) ... it returns a size of 8 bytes 
>-- it rounds Var1 up to a long -- anyone know how to get it to keep Var1
>as a word ?

The compiler probably leaves a gap because it prefers a long to be on a
longword boundary.  If you want to pack the structure more efficiently,
arrange them in size order, e.g. longs, pointers, ints, shorts, chars.

If the order is important, then the Gnu compiler has extensions that can
control the packing of variables (e.g. __attribute(packed)__).  See the
GNU CC manual.  Or you can use a union to create alternative views of
the structure.

regards,

Chris Varlese


- Raw text -


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