www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Null variadic parameter.

reply AJG <AJG_member pathlink.com> writes:
Hi,

How can I test to see if a variadic parameter is null?

I don't think something like:

if (va_arg!(void*)(_argptr) == null) printf("Null");

Is safe.

Thanks,
--AJG.
Aug 17 2005
parent reply "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"AJG" <AJG_member pathlink.com> wrote in message 
news:de0p3i$q1p$1 digitaldaemon.com...
 Hi,

 How can I test to see if a variadic parameter is null?

 I don't think something like:

 if (va_arg!(void*)(_argptr) == null) printf("Null");

 Is safe.

Why wouldn't it be? Casting to a void* is safe, since you can't read or write it.
Aug 17 2005
parent reply AJG <AJG_member pathlink.com> writes:
Hi,

 How can I test to see if a variadic parameter is null?

 I don't think something like:

 if (va_arg!(void*)(_argptr) == null) printf("Null");

 Is safe.

Why wouldn't it be? Casting to a void* is safe, since you can't read or write it.

What if it's a short, or a class, or something else other than an actual pointer, would it still work? Thanks, --AJG.
Aug 17 2005
parent "Ben Hinkle" <ben.hinkle gmail.com> writes:
"AJG" <AJG_member pathlink.com> wrote in message 
news:de0sv9$sj3$1 digitaldaemon.com...
 Hi,

 How can I test to see if a variadic parameter is null?

 I don't think something like:

 if (va_arg!(void*)(_argptr) == null) printf("Null");

 Is safe.

Why wouldn't it be? Casting to a void* is safe, since you can't read or write it.

What if it's a short, or a class, or something else other than an actual pointer, would it still work? Thanks, --AJG.

Check that the TypeInfo of the parameter subclasses TypeInfo_Pointer. That way you'll know the parameter isn't actually a short or a class reference. TypeInfo_Pointer is defined in object.d which is automatically imported so it is always available. Note I haven't actually tried this - I just assume the typeid of a pointer subclasses TypeInfo_Pointer otherwise why have something called TypeInfo_Pointer :-P
Aug 17 2005