including a file

Frits van Bommel fvbommel at REMwOVExCAPSs.nl
Mon Nov 10 02:58:32 PST 2008


Jarrett Billingsley wrote:
> On Sun, Nov 9, 2008 at 10:18 PM, James <james at gmail.com> wrote:
>> i created to include file, 1 with 'module xxx' declaration and the other without it. but i still can import both files. what is the diff here?
>>
> 
> Not a lot.  The module declaration doesn't serve much purpose.  The
> only things I know it's used for is a place to attach documentation
> for the module and as a way to make Rebuild shut up (it will whine
> about the file that doesn't have the module declaration at the top).
> Oh, and if you put an incorrect declaration on a module (say, it's
> foo/bar.d but you put "module bar;" instead of "module foo.bar;"), the
> compiler will sometimes barf.
> 
> I really am not too sure what it's there for.

The module name is used for name mangling. If you have two modules with 
the same name in different packages you'll get name conflicts. And 
without module declarations, the compiler assumes a top-level package 
with a module name derived from the file name.
This is a recipe for trouble if you ever have two modules with the same 
name in different packages.


More information about the Digitalmars-d-learn mailing list