offsetof() operator. A tricky question.

Pavan Vohra vohra at uts.amdahl.com
Sat Mar 10 22:42:30 AEST 1990


I would like to compile in the offsets of structure members.

For example, with this structure

    struct astruct {
      int member0;
      char member1;
    } myastruct;

I want to have, in the same program that the structure appears in,
the number of bytes past myastruct where I can find member1.

The application is an interpreter that will allow one to specify
at run time the structure name and the member name, and to print
the value of structure.member as a decimal or a string depending
on its type.  I will create an array with the offsets and names
of the members and what structures they are members of.  Once this
part of the program is done I will want to write a program that
creates the array.

Do you think that that is a good way to do it?

Has anybody implemented a virtual offsetof() compile-time operator,
or an application similar to mine?  I suppose symbolic debuggers
do it all the time.

-- 
---
Pavan Vohra
Advanced Design Automation Technologies
Amdahl Corporation                     {..hplabs|ames|decwrl}!amdahl!vohra
Sunnyvale, CA 94086-3470               {vohra at uts.amdahl.com}
---



More information about the Comp.lang.c mailing list