How to use/assign NULL to reference types?

Mar 2, 2014 at 2:51 PM
Edited Mar 2, 2014 at 2:53 PM
I have a simple struct that can reference another struct of the same type and it is supposed to do that via a pointer. In the constructor-function of said struct I try to initialize that pointer with null, but get the following error when CUDAfying: Compilation error: [../]CUDAFYSOURCETEMP.cu(14): error: identifier "null" is undefined

I tried using null, and (MyStruct*)0 and it seems to translate that to null, but the compiler is complaining anyways. My Struct:
unsafe struct MyStruct
{
  public MyStruct* Other;

  public MyStruct()
  {
    this.Other = null; // DOESN'T WORK; compiles to "this.Other = null;" though
    this.Other = (MyStruct*)0; // DOESN'T WORK; compiles to the same
    this.Other = default(MyStruct*); // DOESNT WORK; compiles to the same
  }
}
So, how can I assign null?
Mar 2, 2014 at 3:34 PM
Ok, I found a way to assign NULL, but still it feels kinda weird. The question being, is my way the right way? My code:
public static class CUDATools
{
  public static readonly unsafe void* NULL = (void*)0;

  unsafe struct MyStruct
  {
    public MyStruct* Other;

    public MyStruct()
    {
      this.Other = (MyStruct*)NULL; // compiles to "this.Other = (CUDAToolsMyStruct*)NULL;"
    }
  }
}