Compare struct against null
    downs 
    default_357-line at yahoo.de
       
    Tue Apr 29 00:32:40 PDT 2008
    
    
  
Heinz wrote:
> downs Wrote:
> 
>> Heinz wrote:
>>> Hi,
>>>
>>> I have a simple struct and i want to check if a variable has been asigned:
>>>
>>> struct hello
>>> {
>>>
>>> }
>>> ...
>>> hello h;
>>> ...
>>> if(!h)
>>> {
>>> do stuff;
>>> }
>>>
>>> When compiling i get erros about opCall not implemented and many others. What can i do?
>>>
>>> Thanks in advance.
>> Structs are value types. Read the spec. Then use a pointer :)
>>
>> hello* h;
>>
>> if (!h) h = new hello;
>>
>>  --downs
> 
> Thanks for your reply. Can i use then?:
>  hello h;
> if(!&h)
No.
Structs are *value types*.
That means, unless _explicitly newed_ (or part of a struct that's explicitly newed), they _always_ live on the stack.
Ergo, if &h is null, your complete callstack is shot :)
 --downs
    
    
More information about the Digitalmars-d-learn
mailing list