Enum that can be 0 or null

Alex Parrill via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri May 20 18:09:42 PDT 2016


On Friday, 20 May 2016 at 22:10:51 UTC, tsbockman wrote:
> Why do you need to?
>
> Just use null for pointer types, and 0 for integers. D is not 
> C; you aren't *supposed* to be able to just copy-paste any 
> random C snippet into D and expect it to work without 
> modification.
>
> If that's not a satisfactory answer, please show some specific 
> examples of code that you don't know how to make work without 
> VK_NULL_HANDLE so that I can propose a workaround.

Because, as I mentioned in the OP, for VK_NULL_HANDLE to work 
like it does in C on 32-bit systems, it needs to be compatible 
with both pointer types (VkDevice, VkInstance, etc) and 64-bit 
integer types (VkFence, VkSemaphore, many others).

There is of course a workaround: since VK_NULL_HANDLE is always 
zero/null, Vk(Type).init will work as a replacement as long as 
you match up the types. But then people will try to use 
VK_NULL_HANDLE (as every C or C++ Vulkan tutorial or reference 
will instruct) and find out that either a) it doesn't work or b) 
it works fine on their 64 bit development system, but then cause 
a ton of errors when they try to compile their project for a 
32-bit system.

Looks like my best bet is to mark it as deprecated and point them 
to Vk(Type).init instead.


More information about the Digitalmars-d-learn mailing list