is it legal to use a void* in a structure ?
Q. What is a void* ?
A void* is a generic pointer type. It's a pointer but the type pointed to is unknown. You may not dereference a void* but instead must first cast it to another pointer type before you dereference. Also you may not use a void* in any form of pointer arithmeti
so i added it to a typedef
Code:
typedef enum {
UCHAR=1,UINT,UDOUBLE,USTRING
} UNIKIND;
typedef struct _UNIVARLINK {
UNIKIND type;
int arrayc;
char * name;
struct _UNIVARLINK *next;
//void*data;
} UNIVAR;
void createvar(UNIVAR**varstack,char * varname)
{
UNIVAR*p;
//make new var
if(!(*varstack) || !(p=findvar((*varstack),varname)))
{
p = malloc(sizeof(UNIVAR*));
p->name = malloc(strlen(varname)+1);
strcpy(p->name,varname);
p->type = 1;
p->arrayc = 1;
//p->data = NULL;
p->next = (*varstack);
(*varstack) = p;
printf("\n\tCREATING VAR \'%s\'",(*varstack)->name);
}
else
printf("\n\tALREADY VAR \'%s\'",varname);
}
the first time i run createvar everything goes but if i uncomment //p->data = NULL;and //void*data; everything goes wrong
My question : is it illegale to put a void* in a structure