Re: [Dev-C++] Dev-cpp-users Digest, Vol 23, Issue 11
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: <Geo...@ao...> - 2008-05-04 19:23:15
|
Take a look at this information from "The C Programming Language by K&R".
Page 148.
Unions may hold objects of different types and sizes, with the compiler
keeping track of size and alignment requirements.
struct {
char *name;
int flags;
int utype; // Use utype to indicate what the variable type is.....
union u_tag {
int ival;
float fval;
char *sval;
} u;
} symtab[NSYM];
the member ival is referred to as symtab[i].u.ival
the first character of the string sval by either of *symtab[i].u.sval or
symtab[i].u.sval[0]
u is large enough to hold the largest of the three types; the specific size
is implementation-dependent.
if (utype == INT) Do Something;
else if (utype == FLOAT) Do Something;
else if (utype == STRING) Do Something;
else Do Something;
I typed it in fast so check it out. Hope this gives you a clue.
George
**************Wondering what's for Dinner Tonight? Get new twists on family
favorites at AOL Food.
(http://food.aol.com/dinner-tonight?NCID=aolfod00030000000001)
|