"Union busting" and static data.

Postmaster root at vox.darkside.com
Wed Dec 13 16:03:01 AEST 1989


"It is not permitted to initialize unions or automatic aggregates." K&R1

I've resigned myself to using space fillers to get around this limitation.
This is all well & good for mixing two or maybe three types of data.

Is there an elegant way of initializing varying datatypes in a table?
(The purpose is table driven configuration). I refuse to believe that
nobody else has ever had this problem.

(two paragraphs of pruned code):

	int option0; char *option1; char **option2;

	typedef struct {
	  char *option; int type;
	  int *number; char **string; char ***list;
	} Table;

	static Table options[] =
	  {
	  "option0",  STRING,   0,          &option0,    NULL,
	  "option1",  INT,      &option1,   NULL,        NULL,
	  "option2",  LIST,     0,          NULL,        &option2,
	  };

Even if I this were in an ANSI C environment, their handling of unions
is almost as restrictive as K & R 1ed. My current approach can only fit
three or four data types per line.

I would appreciate any ideas regarding solutions to my little dilemma,
and I will summarize for the common good (sniff).

Thomas E. Dell / root at vox.darkside.com



More information about the Comp.lang.c mailing list