webgpu-native / webgpu-headers

**NOT STABLE YET!** See README.
https://webgpu-native.github.io/webgpu-headers/
BSD 3-Clause "New" or "Revised" License
394 stars 45 forks source link

Replace constant defines by static const typed variables #359

Open eliemichel opened 2 months ago

eliemichel commented 2 months ago

This may be a naive question, but is there any reason for these constant values to be declared as macro variables using #define rather than typed static consts?

We already use static const for enum values now so there should be no support issue.

eliemichel commented 2 months ago

(Will update webgpu.yml and gen script if relevant)

kainino0x commented 2 months ago

None of us had strong opinions on which way to go, but it's a bit more traditional. It feels too arbitrary to be worth changing, but I don't know.

kainino0x commented 3 weeks ago

I checked, and this applies to MSVC C but not C++. The pattern this will create problems for is e.g.:

static const uint64_t kMyUsages = WGPUBufferUsage_CopyDst | WGPUBufferUsage_Uniform;

but users can deal with this, by themselves using a macro:

#define MY_USAGES (WGPUBufferUsage_CopyDst | WGPUBufferUsage_Uniform)
kainino0x commented 2 weeks ago

I found a useful series of answers about C here: https://stackoverflow.com/questions/1674032/static-const-vs-define-vs-enum (which was harder to find than the equivalent C++ question here: https://stackoverflow.com/questions/1637332/static-const-vs-define)

Given we probably don't get any significant type safety out of these (they're mostly uint32_t and they're no worse than UINT32_MAX etc.) I would lean weakly toward just keeping the #defines.