Enum that can be 0 or null

Alex Parrill via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri May 20 06:39:50 PDT 2016


(How) can I make a constant that is either zero or null depending 
on how it is used?

Vulkan has a VK_NULL_HANDLE constant which in C is defined to be 
zero. It is used as a null object for several types of objects. 
In D however, zero is not implicitly convertible to a null 
pointer, and vice versa.

On 64 bit platforms, those types are all pointers, so there I can 
define VK_NULL_HANDLE as null. But on 32 bit platforms, some of 
the types are pointers and others are ulongs, and my definition 
of VK_NULL_HANDLE should be compatible with both.

Anyone have an idea on how to make this work?


More information about the Digitalmars-d-learn mailing list