microsoft / DirectXTex

DirectXTex texture processing library
https://walbourn.github.io/directxtex/
MIT License
1.74k stars 426 forks source link

Use fixed width integers for underlying enum types #443

Open Ryan-rsm-McKenzie opened 5 months ago

Ryan-rsm-McKenzie commented 5 months ago

All enums exposed in the api use either the default int or unsigned long for their underlying type. This is an issue for building ffi bindings, because the size of these types vary across platforms. In particular, sizeof(unsigned long) is 4 on windows, but 8 on linux. Based on your code, you expect these enums to have an exact width consistent across platforms, so it should be simple enough to declare all enums using uintN_t as their underlying type.

walbourn commented 4 months ago

The joys of LP64 vs. LLP64.

Type           ILP64   LP64   LLP64
char              8      8       8
short            16     16      16
int              64     32      32
long             64     64      32
long long        64     64      64
pointer          64     64      64

Thanks for the feedback. I'm debating the right solution here. I had originally used DWORD for flags to be consistent with Win32 standards, but over the years I've moved towards C++ standard types wherever possible. Since DWORD is a unsigned long I converted my usage to that so that it would still be the same as using DWORD including the way the types are mangled--there were some really sketchy client scenarios at work.

I don't know that maintaining the link compatibility of DWORD is still needed. I'll need to try some things.