Bug 19159 – `alloca` does not work in -betterC

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2018-08-12T03:55:13Z
Last change time
2024-12-13T19:00:16Z
Keywords
betterC
Assigned to
No Owner
Creator
Mike Franklin
See also
https://issues.dlang.org/show_bug.cgi?id=18788
Moved to GitHub: dmd#19477 →

Comments

Comment #0 by slavo5150 — 2018-08-12T03:55:13Z
extern(C) void main() { import core.stdc.stdlib : alloca; enum length = 20; auto msg = (cast(char*)alloca(length))[0 .. length]; } https://run.dlang.io/is/dHAqPo $ dmd -betterC main.d error: undefined reference to '__alloca' collect2: error: ld returned 1 exit status Error: linker exited with status 1 Works fine with LDC, however: https://run.dlang.io/is/m45jG1 Also, `alloca` should not be in `core.stdc.stdlib`; it's not a standard C function. It may also be better to allocate static arrays on the stack when their length is supplied at runtime. See https://issues.dlang.org/show_bug.cgi?id=18788. That would make `alloca` and `__alloca` just an implementation detail that users wouldn't even need to use directly.
Comment #1 by bugzilla — 2018-08-14T20:13:51Z
alloca() works by calling a compiler-specific function to implement it. This means it has to be customized for each supported C compiler. Currently for dmd, this has only been done for dmc (Win32). Whether it's standard C or not, functions that are in the corresponding compiler's stdlib.h should be in core.stdc.stdlib.
Comment #2 by robert.schadek — 2024-12-13T19:00:16Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/19477 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB