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-20 5:49

>>25
Thanks, fixed it so it doesn't segfault:
char*
allocate_type(type, length)
char type;
unsigned int length;
{
    int* ret = malloc(length);
    *(ret - 3) = type; /* block size is stored at -2 and -1 */
    return ret;
}

int main(int argc, char* argv[])
{
    short* s = (short*)allocate_type('s', sizeof(short));
    long* l = (long*)allocate_type('l', sizeof(long));
    *s = 100; *l = 1000;
    int* p1 = s; int* p2 = l;
    printf("%c, %c\n", *(p1 - 3), *(p2 - 3));
    printf("%d, %ld\n", *s, *l);
    free(s); free(l);
    return 0;
}

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