proposed new construct, offsetof()

PAD Powell padpowell at wateng.UUCP
Thu Oct 25 00:24:28 AEST 1984


I have just been burned again, by a C compiler, and a structure.

I propose the following construct to be added to C:

offsetof( structure_name.field.field.... )

Given the name of the stucture, and the list of the fields, returns the
integer value of the offset from the beginning of the structure, that
will be used in accessing the particular field.

1.  This is useful in DEBUGGING, and finding if you have portable code.
	I have just been burned with 16/32 bit integers.
2.  It provides a "hook" into the compiler which will eliminate all the
	ugly arguements about "offset calculations using 0 pointers"
	which is raging.
3.  In my personal opinion, it is a solution to a problem that requires
	looking at object code, and then guessing what the offset is.

Patrick ("Whimper! first the optimizer gets me, now the structures")
	Powell



More information about the Comp.lang.c mailing list