Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

C halps

Name: Anonymous 2008-03-19 17:18

How do I check what type of variable a variable is?

Something like;
if (typecheck(foo,int))
  {
  /* lol */
  }

Name: Anonymous 2008-03-19 17:37

>>1
I assume you only want to check pointers to memory (anything else seems stupid to me), in this case you can store the type of the memory in an extra byte:

int* pi = malloc(sizeof(int) + 1);
char* pc = pi;
*pc = 'i'; /* i for int */


Then just increment the pointer by one byte when accessing it (I'd use a temporary variable for this).

int* tpi = (((char*)pi)+1);

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List