Loading ...
Sorry, an error occurred while loading the content.

Re: Structure size problem

Expand Messages
  • Nikhil
    ... sorry for quoting the whole thing... I m on vacation, and i m replying thru lynx. I ll reply to some oth flames on the list, after i come back, and have
    Message 1 of 2 , Sep 1 7:45 AM
    • 0 Attachment
      --- In ilughyd@egroups.com, Y Giridhar Appaji Nag <yganag@y...> wrote:
      > Hi!
      > I am using a structure
      > str
      > {
      > u32 a ; // 4 bytes
      > u8 b ; // 1 bytes
      > u16 c ; // 2 bytes
      > }
      > and sizeof(str) gives me a result of 8 bytes
      > *as expected* but I'd like to suppress this
      > so that I get the result as 7 bytes. Is there
      > any compiler flag which would help me do that ?
      > If some one had done this before . . .
      > Note that I have many such "nested" structures
      > and most of these are generated by a code gen
      > and it would be difficult for me to write pad
      > wrappers over them.
      > I tried searching the gcc.gnu.org site and
      > other mailing list archives for this with
      > the keyword round off, pad etc etc. but not
      > with much success. I am not on may mail lists
      > please, this may be posted to other grps like
      > linux-india-programmers :)
      > TIA
      > Giridhar.
      > =====
      > Y Giridhar Appaji Nag
      > yganag@y...
      > http://appaji.webjump.com/
      > __________________________________________________
      > Do You Yahoo!?
      > Yahoo! Mail - Free email you can access from anywhere!
      > http://mail.yahoo.com/

      sorry for quoting the whole thing... I'm on vacation, and i'm replying
      thru lynx. I'll reply to some oth' flames on the list, after i come
      back, and have 'nuff time! ;> Just to put it short, This ISN'T LI, and
      neither does LI own us, and what's written on LI's webpage is
      irrelevant. LI's doing us a service by listing our name on its page.
      oth'wise we dont have any connection. If u want u can give all u're
      flames on LI, if someone doesn't answer u're question. btw, Thaths
      recently put in a well worded mail about such complaints... I'll
      consider forwarding it to the list. 'nuff flame talk fer now.
      As for this, use the GCC extension:
      __attribute__ ((packed))

      u're struct has to be written as:
      typedef struct {
      u32 a;
      u8 b;
      u16 c;
      } __atribute__ ((packed)) str;

      <lame plug>
      I've used this in my Gnome Messaging System.
      In case u haven't seen my post about it, its on gn
      there ain't no webpage there, but u can get it via anonymous CVS at
      there are 2 modules:
      1. server (for the server)
      2. gnomemsg (for the GNOME/GTK+ client)

      </lame plug>

    Your message has been successfully submitted and would be delivered to recipients shortly.