offsetof() macro

dave brown dave at motto.UUCP
Fri Aug 25 05:07:04 AEST 1989


I think I heard somewhere of an offsetof() macro that was proposed for
the ANSI C Standard.  If I've got it right, it would return the
number of bytes from the start of the structure to a given member, i.e.
the offset of the member within the structure.

My questions are:

1. Am I right about such a macro being proposed?

2. Was it accepted?

3. What arguments does it take?  What value does it return?

4. Can it be written for all compilers?  Can one version be portable,
   or would different versions have to be written for different compilers?

5. Can it be used in a static initializer, ex:

	size_t mbr_off = offsetof(...);

5. If it could be portable, can you supply a definition.  If not, can you
   supply one which would work in most cases?

Thanks
	Dave

 -----------------------------------------------------------------------------
|  David C. Brown		|  uunet!mnetor!motto!dave		      |
|  Motorola Canada, Ltd.	|  416-499-1441 ext 3708		      |
|  Communications Division	|  Disclaimer: Motorola is a very big company |
 -----------------------------------------------------------------------------



More information about the Comp.lang.c mailing list