Thread overview | |||||
---|---|---|---|---|---|
|
July 09, 2017 rdmd vs dmd WRT static constructors | ||||
---|---|---|---|---|
| ||||
RDMD does not behave the same as DMD WRT static constructors. The following example, extracted form Mike Parker's "Learning D", does not produce the same result: // stat1.d module stat1; import std.stdio; static this() { writeln("stat1 constructor"); } // stat2.d module stat2; import std.stdio; static this() { writeln("stat2 constructor"); } // statmain.d void main() { } $ rdmd statmain.d stat1.d stat2.d // outputs nothing... $ dmd statmain.d stat1 stat2 $ ./statmain // outputs... stat1 constructor stat2 constructor Bug or intended behaviour? Thanks, Andrew |
July 09, 2017 Re: rdmd vs dmd WRT static constructors | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrew Edwards | On Sunday, 9 July 2017 at 02:57:54 UTC, Andrew Edwards wrote:
>
> $ rdmd statmain.d stat1.d stat2.d
> // outputs nothing...
>
>
> Bug or intended behaviour?
>
rdmd takes the first D file you give it, follows its import tree, and compiles all the modules found there. Anything on the command line after the first source file is treated as a command line argument to the generated program. So stat1.d and stat2.d are never compiled. You'll see if you modify your main function to output the args that it will print the file names you passed.
To include stat1.d and stat2.d in the compilation, you'll either have to import them in statmain.d or use the --extra-file command line switch:
rdmd --extra-file=stat1.d --extra-file=stat2.d statmain.d
|
July 09, 2017 Re: rdmd vs dmd WRT static constructors | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mike Parker | On Sunday, 9 July 2017 at 03:11:17 UTC, Mike Parker wrote:
> On Sunday, 9 July 2017 at 02:57:54 UTC, Andrew Edwards wrote:
>
> To include stat1.d and stat2.d in the compilation, you'll either have to import them in statmain.d or use the --extra-file command line switch:
>
> rdmd --extra-file=stat1.d --extra-file=stat2.d statmain.d
Okay, got it... thanks Mike.
|
Copyright © 1999-2021 by the D Language Foundation