[Issue 24158] ImportC: enums created from string literal #defines don’t implicitly convert to const(char)* in D.

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Nov 19 13:38:33 UTC 2023


https://issues.dlang.org/show_bug.cgi?id=24158

--- Comment #3 from dave287091 at gmail.com ---
One of the issues with the current state is that if you generate a .di file
from the C file, you get a D enum with the expected behavior, but if you
directly import the C file, you trigger the reported problem.

As these are enums collected from macros, they don’t need to follow C
semantics. The C code has already been preprocessor expanded and so don’t use
these defines directly. The collected enums are just for the convenience of the
D user and can follow D semantics.

I ran into this issue when using importC with SDL. Their docs and examples show
code like:

    SDL_bool ok = SDL_SetHint(SDL_HINT_NO_SIGNAL_HANDLERS, "1");

where SDL_HINT_NO_SIGNAL_HANDLERS is a #define. I was able to work around it
with the .ptr workaround, but it seems like the more that examples “just work”
the better.

--


More information about the Digitalmars-d-bugs mailing list