determining if a void* points to a valid Object

BCS BCS at pathlink.com
Thu Aug 17 16:45:39 PDT 2006


Luís Marques wrote:
> BCS wrote:
> 
>> void* ptr;
>> // set ptr;
>> if(null !is cast(Object)ptr)
>> {
>>     // ptr is an object
>> }
>>
>> This should work because type checking is done on object up cast.
>>
>> However it dosn't seem to work.
> 
> 
> According to my experience, from void* to any type it always works. Only 
> from Object to subclasses (or among other types, I guess) it actually 
> does type checking. So if you want to force a cast to another 
> incompatible classe you can do "cast(OtherClass)cast(void*)".
> 
> Luís

casting works but the result is invalid.

This OTOH

cast(Derived)cast(Object)v;

seg-v's on a struct.

Should this be a bug?



More information about the Digitalmars-d mailing list