View mode: basic / threaded / horizontal-split · Log in · Help
August 18, 2005
Null variadic parameter.
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.
August 18, 2005
Re: Null variadic parameter.
"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.
August 18, 2005
Re: Null variadic parameter.
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.
August 18, 2005
Re: Null variadic parameter.
"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
Top | Discussion index | About this forum | D home