I'm exploring a technique in D that may help provide an alternate solution to issue 11666 - Separate each platform's port to its own folder [1].

The idea is to have the same module declaration in multiple files, but guarded by `version`.

// port_linux.d
version (linux):
module port;

// port_windows.d
version (Windows):
module port;

Unfortunately, this fails to compile with the following error:
 Error: Declaration expected, not 'module'

So, it appears the compiler currently requires the module declaration to appear first in the file.

A related issue is 12567 - Modules can't be marked deprecated [2].

* Is this an arbitrary limitation, or is there a technical reason for it? * Would a PR allowing `version()`, attributes, etc... to appear before the module declaration have any unintended consequences?

Thanks in advance for your thoughtful replies,

Mike

[1] https://issues.dlang.org/show_bug.cgi?id=11666
[2] https://issues.dlang.org/show_bug.cgi?id=12567

Reply via email to