[Issue 19159] New: `alloca` does not work in -betterC
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sun Aug 12 03:55:13 UTC 2018
https://issues.dlang.org/show_bug.cgi?id=19159
Issue ID: 19159
Summary: `alloca` does not work in -betterC
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: normal
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: slavo5150 at yahoo.com
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.
--
More information about the Digitalmars-d-bugs
mailing list