You' probably use an integer type to represent the objects, and then the code would be
#define pointer2object(p) ((unsigned long) (p) - 1) #define object2pointer(o) ((struct object *) ((o) + 1)
Should work fine on any traditional C implementation, I think. Could break a conservative garbage collector pretty hard, though.
Anyway I'd prefer to let the machine code generator handle it ;-)
/ Niels Möller (igelkottsräddare)
Previous text:
2003-09-29 21:21: Subject: zero_type();
I see. And compilers won't flip out and do funny code from the necessary casts to offset a pointer like that?
foo = ((struct object *) ((char *) ptr - 1))->foo;
/ Martin Stjernholm, Roxen IS