delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/07/02/12:30:52

From: Erik Max Francis <max AT alcyone DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Size of a struct is not correct
Date: Thu, 02 Jul 1998 09:14:25 -0700
Organization: Alcyone Systems
Lines: 27
Message-ID: <359BB1E1.1593B160@alcyone.com>
References: <01bda5a5$ce48b420$0100a8c0 AT dismuntel DOT ctv DOT es>
NNTP-Posting-Host: charmaine.alcyone.com
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Javier Calleja wrote:

>   I have built the following struct:
> 
>   struct
>   {
>     char one;
>     short two,three;
>     long  four
>   } foo;
> 
>     But when I do sizeof of this struct, the result is wrong (it says
> the
> struct has 12 bytes).

This is perfectly valid.  ANSI says that the compiler can do whatever
padding it deems necessary.  If you need a packed struct (which would
make your program non-ANSI), see the FAQ for more information on what
you can do.

-- 
         Erik Max Francis, &tSftDotIotE / mailto:max AT alcyone DOT com
                       Alcyone Systems / http://www.alcyone.com/max/
  San Jose, California, United States / icbm:+37.20.07/-121.53.38
                                     \
                   Regret it? nope. / Said it? yep.
                                   / Ice Cube

- Raw text -


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