Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!swrinde!elroy.jpl.nasa.gov!ncar!asuvax!stjhmc!f14.n15.z1.fidonet.org!Dave.Harris From: Dave.Harris@f14.n15.z1.fidonet.org (Dave Harris) Newsgroups: comp.lang.c Subject: Help needed with: sizeof (struct a) Message-ID: <14693.286362FE@stjhmc.fidonet.org> Date: 22 Jun 91 14:40:55 GMT Sender: ufgate@stjhmc.fidonet.org (newsout1.26) Organization: FidoNet node 1:15/14 - Nibbles 'n Bits, Orem UT Lines: 40 In a message of , Dave Corcoran (1:114/15) writes: >My Sun cc prints 4 for both structs, prints 3 for the array >-----------------8<-------------------- >struct a {char x;char y;char z}; >struct b {char x[3]}; >char c[3]; >main() >{ > printf("%d\n",sizeof (struct a)); > printf("%d\n",sizeof (struct b)); > printf("%d\n",sizeof c); >} >-----------------8<-------------------- >Is there any way to cause cc to force sizeof return the actual size of >the >structs without rounding up to the next highest sizeof (short)? >Thanx I assume that you are getting 4 when expecting 3? If so... Normally, 4 IS the size of this struct when it is stored in memory. Why you would want 3 returned escapes me. You use the 3 to malloc() (or any number of other address calculations and), you are just asking for bugs. There might be some options that allow you to specify alignment on a byte boundary as opposed to a word boundary. This will cost you some speed however. Dave Harris -- Uucp: ...{gatech,ames,rutgers}!ncar!asuvax!stjhmc!15!14!Dave.Harris Internet: Dave.Harris@f14.n15.z1.fidonet.org