.d files without a module statement? Required to be absent?

Paul Backus snarwin at gmail.com
Sat Nov 14 18:03:35 UTC 2020


On Saturday, 14 November 2020 at 17:55:13 UTC, WhatMeWorry wrote:
>
> I was poking around the dmd code just to "learn from the best" 
> and I came across some files that ended with the .d extension 
> which did not have the module statement. (I was under the naive 
> impression that all .d files must have a module statement)

If a .d file does not have a module statement, the compiler will 
infer the name of the module from the path of the file. So, the 
file `foo/bar.d` will have its module name inferred as `foo.bar`.

There is one exception to this: the file `foo/package.d` will 
have its module name inferred as `foo`, not `foo.package`.


More information about the Digitalmars-d-learn mailing list