Bug 23184 – importC: array length macro doesn't compile

Status
RESOLVED
Resolution
WORKSFORME
Severity
blocker
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2022-06-13T21:58:41Z
Last change time
2022-07-07T06:36:06Z
Keywords
ImportC
Assigned to
No Owner
Creator
ryuukk_

Comments

Comment #0 by ryuukk.dev — 2022-06-13T21:58:41Z
I have no clue how it is called, pardon my ignorance, but i came across that snippet of code that is causing an issue: ``` static const char nk_utfmask[4 +1] = {0xC0, 0x80, 0xE0, 0xF0, 0xF8}; void test() { int a = (int)(sizeof(nk_utfmask)/sizeof(nk_utfmask)[0]); } ``` it is the result of that macro: [1] called here: [2] using clang preprocessor the actual code: ``` static nk_rune nk_utf_decode_byte(char c, int *i) { ((i) ? (void)0 : __assert_func ("./nuklear_all.h", 7976, __func__, "i")); if (!i) return 0; for(*i = 0; *i < (int)(sizeof(nk_utfmask)/sizeof(nk_utfmask)[0]); ++(*i)) { if (((nk_byte)c & nk_utfmask[*i]) == nk_utfbyte[*i]) return (nk_byte)(c & ~nk_utfmask[*i]); } return 0; } ``` [1] https://github.com/Immediate-Mode-UI/Nuklear/blob/11d8acfd4fbb9d0966161fa01d58be15be1974e3/src/nuklear.h#L5455 [2] https://github.com/Immediate-Mode-UI/Nuklear/blob/11d8acfd4fbb9d0966161fa01d58be15be1974e3/src/nuklear_utf8.c#L30
Comment #1 by ryuukk.dev — 2022-06-14T14:50:35Z
This line too is problematic: int len = (int)( (sizeof(nk_utfmask)/sizeof(0[nk_utfmask])) / ((size_t)(!(sizeof(nk_utfmask) % sizeof(0[nk_utfmask])))) );
Comment #2 by bugzilla — 2022-07-07T06:36:06Z
This works when I try it (though size_t was undefined). In general, please provide complete code snippets, rather than incomplete fragments where guessing at what is missing is necessary. I don't know what error you're seeing. But if things don't work for you with the latest compiler, please reopen and supply the error message you see.