C union problems (or is a pointer a pointer?)

Yair Zadik yair at tybalt.caltech.edu
Sat Apr 29 19:36:52 AEST 1989


I like the C++ solution the best: you can declare a union without a name
as long as it is within a struct.  These 'anonymous' unions behave they 
way you would expect them to.  You could just declare:

	typedef struct {
			int a;
			char b;
			union {
				int *c1;
				char *c2;
			      }
			} randomtype;

	randomtype random;

Then you could refer to random.a, random.b, random.c1, and random.c2 just
like in a Pascal record variant.  The only problem is that you need a C++
compiler to handle it.

yair at tybalt.caltech.edu

	

                         
                         



More information about the Comp.lang.c mailing list