Some Basic Questions

Frank Benoit keinfarbton at
Tue Aug 15 04:39:44 PDT 2006

> I have each of my classes in separate source files. the files are named the 
> same as the class.  Is it true that each source files is compiled to a 
> separate module? 

Every source file is a module. Each module (=src file) is compile to a
object file.

> That a module needs to import any other module to access its classes?


> These modules are the obj files right? 
No, its the source files.

> Where is it getting the name of the modules from? 

The path the source file is located in, has to match the
module-statement in the source file.


module mypackage.mymod;
map to the file

> My source files are
> capitalized but from the looks of things module names need to be lowercase.

The case is important, but you can name the modules/files like you want.

> Or at least the first letter needs to be. eg. TaskArea class is save in 
> TaskArea.d but I need to import taskArea to access the class.  By disabling 
> clean I see that this is the name of the generated obj file. How come it 
> changes case on me? Should I stick with this naming convention for my 
> sources?

You really do not need the mapping 1 module == 1 class.
You can put 3 classes into one module if you want. The module name and
the class name are independent. They can be equal, but doesn't have to.
They have different scopes.

> Also, how does the dot syntax work?

If you mymodule contains the class 'MyClass' then:
mypackage		=> qualifies the package
mypackage.mymodule	=> qualifies the module, needed to import
mypackage.mymodule.MyClass => is the full qualified name of the class

The dot syntax is only unique if a file mymodule.d is found in a
mypackage directory. If not it could also mean a module 'MyClass' in the
directory mypackage/mymodule or it can mean a inner class MyClass in the
class 'mymodule' in the module 'mypackage' :)

> I've downloaded and using TinyXML. I've dropped the sources in a folder 
> called TinyXML. To access this i need to import tinyxml.tinyxml not 
> TinyXML.tinlyxml. So the dot syntax is used to find objs in subfolders? And 
> it also requires lowercase?

If you work on windows, its possible the case sensitivity is affected
from the file system. I don't know. I work on linux.
You have to make sure, the module statements of the tinyxml modules
match the directory structure, and the root of this structure is one of
the compiler include paths (option -I). I don't know the TinyXML so I
cannot help further.

> But then what is with std.stdio? I don't see an std folder? Is this a special 
> case?

look into the dmd/source/phobos folder. This directory is also listed in
sc.ini, that is the cause, the compiler looks there.

> When i import dwt.all for GUI, it seems to be compiling all of it it every 
> time I build. Do I really need to recompile all of dwt every time i build? 

compiling is made in several steps. If you import a module, it is parsed
to extract all definitions. Only if you compile the whole semantic
parsing is done. Well, I think that is the way it works :)

More information about the Digitalmars-d-learn mailing list