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 6:01

>>45
that's hackish bullshit
Have an opaque object instead

#include <stdio.h>
#include <stdlib.h>

#define P(x) (x).ptr
#define T(x) (x).type
#define ALLOC(x, t) T(x) = #t, P(x) = malloc(x)
#define FREE(x) free(P(x))

typedef struct {
  void *ptr;
  const char *type;
} alloc_t;

int main(void) {

  alloc_t foo;
  foo = alloc(1024, int);
  printf("foo = %s\n", T(foo));
  FREE(foo);

  return 0;
}

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