proposed new construct, offsetof()

M. G. Hand marcus at pyuxt.UUCP
Sat Oct 27 05:11:25 AEST 1984


Well,  if you really want to know what the actual offset into your
data structure is (as opposed to some logical naming method like
struct.mem) you should try using BCPL instead of C.  Try this:

	LAST.LIST!NEXT := NEWVEC(SIZE.OF.LIST)
	LIST.MEM := LAST.LIST!NEXT
	PACKSTRING(LIST.MEM!NAME, "a string")

where NEXT and NAME are simple integers giving offsets into the vector
returned by NEWVEC.   Ie you get a simple contiguous block of BCPL words
and its is up to you how you partition it.  To get machine portability
you are guaranteed the manifets constants BCPLBYTESPERWORD and BITSPERBYTE
which can be used as scaling factors.   Fun, eh?

		marcus



More information about the Comp.lang.c mailing list