#Something like `nullptr`?

1 messages · Page 1 of 1 (latest)

split snow
#

I saw that undefined is not comparable so the following code doesn't work:

// ...
var abc: *MyStruct = undefined;
if (MyStruct == undefined) {
  // STUFF
}
// ...

So is there a way to check whether the pointer is available or not like nullptr?

Thanks!

frigid condor
#

*MyStruct, cannot be null, it will always point to something

#

if you want a nullable pointer, you need to use ?*MyStruct

split snow
frigid condor
#

a *thing in c++ is a ?*thing in zig, because all pointers there are nullable

#

zig pointers are non-nullable, you need to make them optional if you want null to be a valid value