Uninitialized object hangs without warning.
    bearophile via Digitalmars-d-learn 
    digitalmars-d-learn at puremagic.com
       
    Wed Nov 26 01:38:10 PST 2014
    
    
  
Bear Cherian:
> Class MyClass{
>
>     this(){}
>
>     void someFunction(){
>         //body
>     }
>
> }
>
> And in my app I had something like
>
>     MyClass classObject;
>     classObject.someFunction();
>
> When I compile, no warnings or errors.
If you compile that code (with lowercase Class) with -O the 
compiler finds the bug:
class MyClass {
     this() {}
     void someFunction() {
         //body
     }
}
void main() {
     MyClass classObject;
     classObject.someFunction;
}
test.d(11,5): Error: null dereference in function _Dmain
But in more complex cases the compiler doesn't.
Bye,
bearophile
    
    
More information about the Digitalmars-d-learn
mailing list