I would use a void pointer and cast it whenever I need it. You can't directly store the type of it but you still can use an int variable to access the right function in an array of function pointer that will use the right cast.
typedef struct stack
{
void *val;
int type;
struct stack *next;
}node;
With type matching one function of your array of function pointer. How can I use an array of function pointers?
You can also make a simple switch case on your "type" (definitely appropriated).
Edit: simple example:
while (root != NULL)
{
switch (root->type) {
case 0:
printf("%d\n", *(int *)(root->val));
break;
case 1:
printf("%c\n", *(char *)(root->val));
break;
default:
printf("unexpected type\n");
}
root = root->next;
}
It would probably make more sens with a char instead of an int so you could just do case 'c', case 'i'.
Be careful, you have a void *, it's a pointer to your variable, don't forget to allocate it.
root->val = malloc(sizeof(int));
*(int *)(root->val) = 2;