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 4:49

>>40
face.pdb

Name: Anonymous 2008-03-20 5:02

>>40
I was talking to ``No, a "long" / DWORD is 4 bytes.'' person.

Also, if you were serious in >>35, you are a dumbass, same types having different sizes on different machines have nothing to do with this.

Name: Anonymous 2008-03-20 5:16

>>42
No it has exactly to do with this.

Name: Anonymous 2008-03-20 5:40

We have beet trolled constantly.

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;
}

Name: Anonymous 2008-03-20 5:53

>>26
That's how variants work in COM.

Name: Anonymous 2008-03-20 5:56

>>13
Please learn Haskell and you will understand >>7. You might also cease being an asshole. Thank you.

Name: Anonymous 2008-03-20 5:58

DWORD = 4 bytes

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;
}

Name: Anonymous 2008-03-20 6:09

Name: Anonymous 2008-03-20 6:09

>>49
that's hackish bullshit
Have a LISP VM instead

(car (cdr NIL))

Name: Anonymous 2008-03-20 6:35

>>51
that's hackish bullshit
Have a Scheme instead

(cons car cdr)

Name: Anonymous 2008-03-20 7:13

>>52
that's hackish bullshit
Have a BBcode enhanced post instead

Name: Anonymous 2008-04-03 13:44

>>13
hahaha learn Haskell and then bash >>7 again, asshole.

Name: Anonymous 2008-04-03 14:01

What the shit, this thread is over, die.

Name: Anonymous 2008-04-03 14:41

>>54
Have some improperly nested bbcode for your amusement.

Name: Anonymous 2008-04-04 17:45

Why would OP want to test for the type of a variable anyhow? Can't he just look at the damned declaration?

Name: Anonymous 2008-04-04 17:47

>>57
RTTI.

Name: Anonymous 2008-04-05 0:30

>>58
Pronounced Ritty

Name: Anonymous 2010-12-26 8:37


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