TIP: Click on subject to list as thread! ANSI
echo: c_echo
to: Jasen Betts
from: Bill Birrell
date: 2003-08-08 00:36:00
subject: sizeof()

Hi Jasen,

 > Given

 > typedef struct moo
 >   {
 >  int foo;
 >  char bar;
 >   } moo;


 > is   sizeof(moo) * 100   always the same as   sizeof(
 > moo[100] )

    I think so. I'm not at all sure that moo[100] means anything at all
unless the array of structures is declared and consequently storage is
allocated.

 > in other words does sizeof() include any slack space
 > required for
 > alignment.

    Sizeof() returns the actual number of bytes of the dingus in the
brackets. Sizeof(moo) * 100 should return 300 with byte alignment. The
sizeof(an array of 100 structures of type moo) would also depend on
alignment. However unless you change alignment within the program they
should be the same.

    This might be a dangerous assumption with modular compilation and later
linking unless you take care that all modules specify the same alignment. I
did come across this problem reading in and then interpreting a data file
compiled with PASCAL. In that case program alignment had to match the data
file.

    Darin McBride should be able to answer this off the top of his head.

Best Wishes,
Bill.

---
* Origin: Escan BBS (2:25/200)
SEEN-BY: 633/267 270
@PATH: 25/200 108 252/110 250/501 140/1 106/2000 633/267

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.