Suppose I have several C structures for which I would like to use a specific set of functions.
I am wondering if the legal approach is:
typedef struct Base { int exampleMember;
In this example, you will notice that both the Foo and Bar structures begin with a Base member.
And, in MethodOperatesOnBase , I applied the void * parameter to Base * .
I would like to pass pointers to Bar and pointers to Foo to this method and rely on the first member of the structure as a Base structure.
Is this acceptable or are there some (possibly compiler specific) issues that I need to know about? (For example, some kind of packing / filling scheme that will change the location of the first member of the structure?)
c
Steve Sep 05 '11 at 20:40 2011-09-05 20:40
source share