digitalmars.D.bugs - [Issue 20377] New: extern(C) void main(string[] args) has invalid
- d-bugmail puremagic.com (32/32) Nov 09 2019 https://issues.dlang.org/show_bug.cgi?id=20377
https://issues.dlang.org/show_bug.cgi?id=20377 Issue ID: 20377 Summary: extern(C) void main(string[] args) has invalid 'args' Product: D Version: D2 Hardware: x86_64 OS: Linux Status: NEW Severity: enhancement Priority: P1 Component: dmd Assignee: nobody puremagic.com Reporter: mipri minimaltype.com The following complete program succeed when run with no arguments. What it should do is fail on the second assert. extern(C) void main(string[] args) { import core.stdc.stdio: printf; assert(args.length == 1); assert(args[0].ptr == null); } When 'extern(C)' is removed, this code fails as args[0] contains the path used to invoke the program, as provided by the OS. I noticed this when trying to write an extremely simple C program in D, with -betterC, where I spent more than 20 minutes being perplexed by 'impossible' NULL dereferences. The behavior comes with the extern(C) however, and doesn't require a -betterC flag. This behavior is observed with LDC 1.15.0 and DMD64 D Compiler v2.086.1, and with the nightly DMD build of v2.089.0-rc.1-master-2bbd37b extern(C) void main(int argc, char **argv) works fine, but I argue if string[] args isn't supported, compilation should fail with an error instead of providing the current behavior. --
Nov 09 2019