Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!mips!news.cs.indiana.edu!ux1.cso.uiuc.edu!ux1.cso.uiuc.edu!allender From: allender@ux1.cso.uiuc.edu (Mark Allender) Newsgroups: comp.lang.c Subject: Little problem with sizeof on PC Message-ID: <1991Apr23.022057.29511@ux1.cso.uiuc.edu> Date: 23 Apr 91 02:20:57 GMT Sender: usenet@ux1.cso.uiuc.edu (News) Reply-To: allender@ux1.cso.uiuc.edu (Mark Allender) Organization: TechoPunks Ltd. -- Party Goers to the Max Lines: 50 I'm having a litle problem that I have a suspicision about, but want to clarify. Here's the situation.... I have a structure that is defined like: struct header { int version[2]; char unused[40]; int stuff[8]; char bogus; char mode; int time; char unused2[90]; char filler[38]; char filler2[15] float number; }; The total size of the structure is 201 bytes (count it if you wish....). Now, I want to read the beginning of a binary file into this structure, so I do something like this: struct header Header; if ((readnum = read(fd, (char *)(&Header), sizeof(Header))..... Things don't seem to get done correctly at this point. A little investigation shows that sizeof(Header) return 202, and not 201. This is clearly not what I want to do. Now, I kind of figure that the problem has to do with the way structure members are lined up in memory. Am I correct in thinking that since there are an odd number of bytes in the structure (201), that sizeof(Header) returns an even number since things have to be word aligned (with a word being 2 bytes)? This would seem to make some sense. In any case, what is the best way around this problem. Could I do something like if ((readnum = read(fd, (char *)(&Header), sizeof(Header) - 1)).... Seems like kind of a bad way to fix things.... Any help would be appreciated... -Thanks in advance... -Mark Allender -University of Illinois at Urbana/Champaign -Conversation Builder Project -allender@cs.uiuc.edu