T
Tom Plunket
The project I'm currently on makes heavy use of unnamed structures to
represent an "object hierarchy" of a sort.
E.g.
struct BaseObject
{
int aMember;
int anotherMember;
// etc.
};
struct GameObject
{
struct BaseObject;
int yetAnotherMember;
// etc.
};
Doing so facilitates the use of the BaseObject's members, so a
function might be able to do:
void fn(GameObject* g)
{
g->aMember = 4;
g->anotherMember = 6;
g->yetAnotherMember = 839;
}
However, coming from a C++ background myself (in recent history,
anyway), this sort of thing horrifies me on many levels. Even when I
was a C programmer exclusively (almost ten years now past!), I never
saw this functionality used on any actual project.
My question, finally, is, "is this sort of thing frequently used by
'real' C programmers?" I suppose the answer may come down to your
view of object oriented concepts, but even from a purely procedural
point of view, I don't like the idea of not being able to easily
figure out where a member actually lives. Bear in mind that this
method is used substantially, and it is not uncommon for an "object
hierarchy" so-constructed to be 10 levels deep. ...that of course
brings with it its own challenges, but I'm mostly interested in how
"real" C coders view unnamed member variables and their use as
demonstrated above.
thanks for any insight,
-tom!
represent an "object hierarchy" of a sort.
E.g.
struct BaseObject
{
int aMember;
int anotherMember;
// etc.
};
struct GameObject
{
struct BaseObject;
int yetAnotherMember;
// etc.
};
Doing so facilitates the use of the BaseObject's members, so a
function might be able to do:
void fn(GameObject* g)
{
g->aMember = 4;
g->anotherMember = 6;
g->yetAnotherMember = 839;
}
However, coming from a C++ background myself (in recent history,
anyway), this sort of thing horrifies me on many levels. Even when I
was a C programmer exclusively (almost ten years now past!), I never
saw this functionality used on any actual project.
My question, finally, is, "is this sort of thing frequently used by
'real' C programmers?" I suppose the answer may come down to your
view of object oriented concepts, but even from a purely procedural
point of view, I don't like the idea of not being able to easily
figure out where a member actually lives. Bear in mind that this
method is used substantially, and it is not uncommon for an "object
hierarchy" so-constructed to be 10 levels deep. ...that of course
brings with it its own challenges, but I'm mostly interested in how
"real" C coders view unnamed member variables and their use as
demonstrated above.
thanks for any insight,
-tom!