Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 14 Mar 1999 20:51:14 -0600 (CST)
From:      Alec Kloss <alec@d2si.com>
To:        mturpin@saturn.spel.com (Mark Turpin)
Cc:        questions@FreeBSD.ORG
Subject:   Re: Programming Question
Message-ID:  <199903150251.UAA91257@macbeth.d2si.com>
In-Reply-To: <Pine.BSF.4.05.9903141646550.6443-100000@saturn.spel.com> from Mark Turpin at "Mar 14, 1999  4:50:32 pm"

next in thread | previous in thread | raw e-mail | index | archive | help

Mark Turpin said:

> 
> 
> I feel really silly having to ask this.
> 
> Why does my sizeof(mystruct) come out as 4 instead of 3 ( short + char ) ?
> 
> 	struct {
> 	   short	shortvariable;
> 	   char		charvariable;
> 	} mystruct;
> 
> 	sizeof(mystruct) == 4
> 
> Thanks
> 
> 
> 

Things (like the short) must be aligned on even-byte addresses.  C treats
this structure like it is size 4 to insure that arrays of them maintain their
alignment.



To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199903150251.UAA91257>