How to get a byte offset

S. T. Tan swie at cs.umn.edu
Mon May 28 13:46:43 AEST 1990


Is there an easy way to get the byte offset of a field in a structure without
counting it manually ?
The reason I don't want to count the offset manually is, the size of the 
"int"-type is machine dependent (may be 2 bytes or 4 bytes).

example: struct {
           int	a;
           char	b[3];
           int	c[10];
           char	d;
         } my_struct_type;

What would be the offset of "d" ?

Please e-mail the answer to me directly since it seems to me that the answer is
trivial.

Thanks in advance
swie at umn-cs.cs.umn.edu



More information about the Comp.lang.c mailing list