[Tfug] OT: sizeof *part* of a struct

Bexley Hall bexley401 at yahoo.com
Thu Apr 1 14:04:01 MST 2010


Hi Mike,

> If payload is always at the end, try offsetof(Foo, payload).

Yeah, I thought of that but it isn't extensible.  E.g., imagine if
there were lots of other cruft in the Foo -- peers with payload.
You might want to pick and choose which sizeof's to include in
an expression (without forcing all of them to be contiguous *and*
at certain places in the struct)

> Otherwise it's probably easiest to define a type for
> payload:
> typedef union {
>    stuff
>    otherstuff
> } Payload;

That's what I've done as a workaround.  But, it adds extra
clutter as each of these "peers" now needs to be promoted to a
first-class type *just* to get its size...  :<
 
> On Thu, 1 Apr 2010, Bexley Hall wrote:
> 
> > Hi,
> >
> > I'm trying to find safe syntax for the following:
> >
> > typedef struct foo {
> >   blah-blah-blah;
> >   union {
> >      stuff
> >      otherstuff
> >   } payload;
> > } Foo;
> >
> > #define OVERHEAD (sizeof(Foo) - sizeof(Foo.payload))
> >
> > Suggestions?
> >
> > Thx,
> > --don
> >
> >
> 
> -- 
> Mike Fitzgibbon       
>     MRFitz at ns.arizona.edu
> 
> 
> _______________________________________________
> Tucson Free Unix Group - tfug at tfug.org
> Subscription Options:
> http://www.tfug.org/mailman/listinfo/tfug_tfug.org
> 


      




More information about the tfug mailing list