Something new for C?

Richard A. O'Keefe ok at quintus.uucp
Tue Nov 8 18:41:25 AEST 1988


In article <73 at dsoft.UUCP> root at dsoft.UUCP (Super user) writes:
>Maybe I've missed something in C, but One of the things I've never found a way
>to do and have always wanted, was a precompiler command to allow me to use
>the offset of an item into a structure. for example:

This is one fo the things that has been easy to do for a long time.
If you're using a UNIX(tm) system, you may already have a header file
/usr/include/struct.h, which defines

	fldoff(Structure_TAG, Field_Name)
	fldsiz(Structure_TAG, Field_Name)

Modulo parens:

	fldoff(Tag, Field) = ((int) &((struct Tag *)0)->Field)
	fldsiz(Tag, Field) = (sizeof ((struct Tag *)0)->Field)

This may give trouble on some 80*86 C compilers.  ANSI C will have
an "official" offsetof macro.  I couldn't find the file on a V.3 '386
system, but the macros worked fine.



More information about the Comp.lang.c mailing list