Some Basic Questions
derek at psyc.ward
Tue Aug 15 06:10:19 PDT 2006
On Tue, 15 Aug 2006 21:10:47 +1000, Jay Kyburz wrote:
>> I always use the 'build' tool from http://www.dsource.org/projects/build
>> to compile and link an executable in one step. It searches for all files
>> and calls dmd with the right parameters.
> Thanks for those notes Sean and Frank, and yeah, I've been using build.exe
> too, and with no problems. Everything is working fine and happily coding away
> on my little project.
Glad its been useful for you.
> I guessed a few things that I would like to know for sure though.
> Heres another question. I have lots.
> 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?
Yes. A source file *is* a module. The resulting .obj file is the module in
'object' form and can be linked in with other modules to form the
> That a module needs to import any other module to access its classes?
> These modules are the obj files right?
> Where is it getting the name of the modules from?
If your source file does *not* have a module statement in it, then the
module name is the same as the source file minus the '.d' suffix. Otherwise
the module name is what you've declared in the module statement.
In nearly every case, the best practice is to have a module statement that
is exactly the same as your source file name. It saves headaches later on.
> My source files are
> capitalized but from the looks of things module names need to be lowercase.
They don't absolutely need to be lowercase, but the recommended standard is
to make module names (and thus file names) all lowercase.
> 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
No, I suggest you use a different naming convention. I would have your
class name start with a Capital letter and have your source file name all
lowercase. And if you stick to one class per file, have your filename
different to the class by adding a suffix or prefix. For example,
You can have multiple classes in a single file. One would typically do that
if those classes needed direct access to each other's internals without
having to go through member functions. Everything in a module has access to
everything else in the same module (if in scope of course).
> Also, how does the dot syntax work?
If the module name is "foo.bar", it implies that the source file is to be
found in "foo\bar.d". Note that module names are *not* relative to the
current folder or the folder of the file importing the module. They are
relative to an entry in the 'Import List' of folder names. This list is
defined in dmd\bin\sc.ini and can be added to by the -I switch (dmd only).
My Build utility analyzes the source files to discover what the right
Import List should be and automatically adds them to the list before it
compiles the souirces.
> 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?
This is why one should stick to lowercase file names as they are portable
> But then what is with std.stdio? I don't see an std folder? Is this a special
No it is not special. "std.stdio" is a module found in "std\stdio.d". This
is relative to an entry in the Import List. The default Import List is
usually "c:\dmd\src\phobos" and can be found in sc.ini as
> 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?
Probably not, but its so fast it doesn't hurt. Also, there are some
remaining limitations with templates and -release mode that is often fixed
by doing a full compile.
"Down with mediocrity!"
More information about the Digitalmars-d-learn