Pointers and Offsets and Shared Memory Concerns

Greg Hunt hunt at hobbit.DG.COM
Fri Sep 29 10:40:23 AEST 1989


Try this (it works for me under GCC):

#define MEMBER_OFFSET(mo_struct, mo_member) \
    ((int32_type) (char_type *) & (((mo_struct *) 0) -> mo_member))

The following operation is allowed with MEMBER_OFFSET:

    typedef any_struct_type {
        .....
        <type>          member_name_within_struct;
        .....
    } ANY_STRUCT_TYPE;

    <int32_type> = MEMBER_OFFSET (ANY_STRUCT_TYPE,
                                  member_name_within_struct);

Note that the "structure type" passed MUST be a typedef structure
name, not a typedef tag name, nor an instance of the structure.  The
member name must be within the structure, and can be any type except
bit field.

I define int32_type as long int and char_type as char.  

Hope it works for you.  

------------------------------------------------------------------
Greg Hunt                   Internet: hunt at dg-rtp.dg.com
Data General Corporation    UUCP:     {world}!mcnc!rti!dg-rtp!hunt
RTP Software Development
RTP, NC. 27713



More information about the Comp.lang.c mailing list