From: Thomas Demmer Newsgroups: comp.os.msdos.djgpp Subject: Re: The size of structures and binary files Date: Fri, 13 Jun 1997 15:53:28 +0100 Organization: Lehrstuhl fuer Stroemungsmechanik Lines: 37 Message-ID: <33A15EE8.794B@LSTM.Ruhr-UNI-Bochum.De> References: <33A1B030 DOT 309E AT post DOT psychologie DOT uni-bielefeld DOT de> NNTP-Posting-Host: bvb.lstm.ruhr-uni-bochum.de Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk News Administrator wrote: > > Dear DJGPP users! > > Recently I came across something weird: > I have two structs: > struct s1 { char c1; char c2; short s}; > struct s2 { char c1; short s; char c2}; > > A call to sizeof will return 4 for s1 and 6 (!) for s2. > It seems like the size of the chars in s2 gets increased to 2. > [...] Welcome to the world of alignment. Just say #pragma pack(1) struct s1 { char c1; char c2; short s}; struct s2 { char c1; short s; char c2}; #pragma pack() -- Ciao Tom ************************************************************* * Thomas Demmer * * Lehrstuhl fuer Stroemungsmechanik * * Ruhr-Uni-Bochum * * Universitaetsstr. 150 * * D-44780 Bochum * * Tel: +49 234 700 6434 * * Fax: +49 234 709 4162 * * http://www.lstm.ruhr-uni-bochum.de/~demmer * *************************************************************