Bug 23213 – ImportC - variable length array does not compile

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
All
Creation time
2022-06-25T21:18:31Z
Last change time
2022-07-07T07:47:15Z
Keywords
ImportC, pull
Assigned to
No Owner
Creator
ryuukk_

Comments

Comment #0 by ryuukk.dev — 2022-06-25T21:18:31Z
The following code doesn't compile: test.c(4): Error: variable `n` cannot be read at compile time ``` void hello() { int n = 0; // some stuff int fds[n == 0 ? 1 : n]; } ``` It is valid C code, taken from: https://github.com/cesanta/mongoose/blob/2bbb2bb1dbbc134c390babd43e474028ede8e8a5/mongoose.c#L3921-L3923
Comment #1 by aldacron — 2022-06-26T04:38:09Z
Well, it's valid C in C99. ImportC is a C11 compiler. In C11, support for VLAs is optional. Compilers that don't support them are supposed to define the __STDC_NO_VLA__ macro.
Comment #2 by maxhaton — 2022-06-26T05:03:52Z
This could be lowered to something on the heap fairly easily I think.
Comment #3 by ryuukk.dev — 2022-06-26T09:03:55Z
why on the heap? it should be on the stack, i used alloca instead and i could compile the library
Comment #4 by ryuukk.dev — 2022-06-26T10:47:55Z
(In reply to Mike Parker from comment #1) > Well, it's valid C in C99. ImportC is a C11 compiler. In C11, support for > VLAs is optional. Compilers that don't support them are supposed to define > the __STDC_NO_VLA__ macro. Thanks, i sent a PR on that library's repo and left a note about this macro Should this be marked as resolved?
Comment #5 by aldacron — 2022-06-26T11:09:01Z
No, please leave it open. Walter will have to decide which way to go with this.
Comment #6 by dlang-bot — 2022-07-07T06:53:26Z
@WalterBright created dlang/druntime pull request #3872 "fix Issue 23213 - ImportC - variable length array does not compile" fixing this issue: - fix Issue 23213 - ImportC - variable length array does not compile https://github.com/dlang/druntime/pull/3872
Comment #7 by dlang-bot — 2022-07-07T07:47:15Z
dlang/druntime pull request #3872 "fix Issue 23213 - ImportC - variable length array does not compile" was merged into master: - dee0164ae940f39a588fc9e135ece355e8e875ed by Walter Bright: fix Issue 23213 - ImportC - variable length array does not compile https://github.com/dlang/druntime/pull/3872