
Run-time type information
Quote:
> Is there any way to get the type information of a variable during
> run-time, without having to devise a new typing mechanism or
> modifying the C's compilation system ?
Well, it depends a bit on what you mean by typing mechanism, but
the easiest way to do this is probably to add tag identifiers to
the structure, eg...
#define TYPETEST 1
typedef struct TEST {
int type;
int i;
char *c;
double f;
} TEST;
Then given a function that takes a pointer and needs to determine
its type, you can do something like...
void Lukito(p) /*========================================*/
void *p;
{
switch (*(int *)p) {
case (TYPETEST):
{
TEST *pT;
pT = (TEST *)p;
...
}
break;
...
}
}
Depending on what you want to do with these structures, you may
find it useful to also add a structure length field after the type
field, etc.
Quote:
> Lukito
--
*** Count Templar, ELITE, Cobra Mk III (FM-287) ***