gnu@sun.uucp (John Gilmore) (12/08/83)
The other advantage to unique member names (besides portability to V7
and minor readability) is that you can substitute them with #define's.
It's a royal pain to try to change a nonunique member name (which is
why all the V7 people complain when we use them) -- it has to be done
manually.
While we're almost on the subject, does anybody have a better
workaround for getting rid of the "extra member name" required when
making a union? e.g.
struct foo {
char *name;
union {
int i;
float f;
} u;
} node;
You can't talk about "node.i" or "node.f", you have to say "node.u.i".
I find this a royal pain and end up doing this:
struct foo {
char *name;
union {
int u_i;
float u_f;
} u;
#define i u.u_i
#define f u.u_f
} node;
Then I can say "node.i" and cpp turns it into "node.u.u_i" which works.
However, "i" and "f" have to be unique in the whole program, since cpp
doesn't know about scope (or that they only apply within struct foo's).