On Jul 8, 2005, at 2:33 AM, Nicholas Clark wrote:
I think you need INT2PTR() defined and described in perl.h.
Right on! For reference, here is the relevant section of perl.h,
taken from the 5.8.7 source.
/*
* The macros INT2PTR and NUM2PTR are (despite their names)
* bi-directional: they will convert int/float to or from pointers.
* However the conversion to int/float are named explicitly:
* PTR2IV, PTR2UV, PTR2NV.
*
* For int conversions we do not need two casts if pointers are
* the same size as IV and UV. Otherwise we need an explicit
* cast (PTRV) to avoid compiler warnings.
*/
#if (IVSIZE == PTRSIZE) && (UVSIZE == PTRSIZE)
# define PTRV UV
# define INT2PTR(any,d) (any)(d)
#else
# if PTRSIZE == LONGSIZE
# define PTRV unsigned long
# else
# define PTRV unsigned
# endif
# define INT2PTR(any,d) (any)(PTRV)(d)
#endif
#define NUM2PTR(any,d) (any)(PTRV)(d)
#define PTR2IV(p) INT2PTR(IV,p)
#define PTR2UV(p) INT2PTR(UV,p)
#define PTR2NV(p) NUM2PTR(NV,p)
#if PTRSIZE == LONGSIZE
# define PTR2ul(p) (unsigned long)(p)
#else
# define PTR2ul(p) INT2PTR(unsigned long,p)
#endif
Also, this from config_h.SH:
/* PTRSIZE:
* This symbol contains the size of a pointer, so that the C
preprocessor
* can make decisions based on it. It will be sizeof(void *) if
* the compiler supports (void *); otherwise it will be
* sizeof(char *).
*/
#define PTRSIZE $ptrsize /**/
I *think* that this is correct:
return (INT2PTR(Soldier*,SvIV(SvRV(obj))))->name;
but it's not tested.
More worrisome, it's not documented in perlapi. I've set a minimum
requirement of Perl 5.8 for Kinosearch, so it's probably not a big
deal when INT2PTR was added. And I wouldn't mind being a guinea
pig. But if you folks ever change up the definition on me things
could get messy.
That code utilizing INT2PTR looks right, but should I be paranoid and
roll my own macro?
Marvin Humphrey
Rectangular Research
http://www.rectangular.com/