module vs import

Lars Ivar Igesund larsivar at igesund.net
Sun Jun 8 12:44:26 PDT 2008


Tomasz Sowif1ski wrote:

> Robert Fraser Wrote:
> 
>> The "module" keyword is used to assign a name to your module (which
>> incidentally must coincide with its filename & folder structure) while
>> "import" gives you access to the module with the given name.
> 
> By the way, why do you have to repeat the filename in the file itself? I'm
> sure there must be some reason, but I can't see it now.
> 
> Tomek

It is only really omittable if you have no hierarchy. The full module name
is used in the symbol name mangling (for instance when compiling an object
from a module using the -c switch). When you import the same module using
the module name (say foo.bar.Util), your application will only link if the
mangling (and module names match). The compiler can't guess the hierarchy
specified by the importing code when that code isn't part of the compile.
For all-at-once compiling, the compiler probably could get it right.

Lars Ivar Igesund
blog at http://larsivi.net
DSource, #d.tango & #D: larsivi
Dancing the Tango


More information about the Digitalmars-d-learn mailing list