www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - separate and/or independent compilation

reply Tibi <giurgiu.tibi gmail.com> writes:
Can someone please tell me a few words about separate compilation in D. A small
example would be nice, if I`m not asking too much.

And one more thing, I haven`t understood very well what import does, is it
similar to the #include statement from C++ or is it somewhat different?
Jun 07 2007
next sibling parent reply Myron Alexander <someone somewhere.com> writes:
Tibi wrote:
 Can someone please tell me a few words about separate compilation in D. A
small example would be nice, if I`m not asking too much.
 
 And one more thing, I haven`t understood very well what import does, is it
similar to the #include statement from C++ or is it somewhat different?
Tibi, The import statement is more similar to Python (or Java) than to C/C++. The #include statement instructs the c/c++ pre-processor to include source into the current source file which is why you have to be careful about what you put in the included file and also why you should have guards. In D, the import statement imports a compiled module, not source. Modules are actually similar to classes in that they have constructors, destructors, public and private elements, and they provide a namespace. Their purpose is to provide functionality that the application can use, whether this is module globals, functions, classes, structs, type definitions, template definitions etc. In a module, you do not separate the declaration from the implementation, your implementation is the declaration. Modules are a phenomenal tool for library writers, and they also provide a great way to break up an application into functional units. In one sentence, modules provide the functionality of #include (and so much more) but with "special" binaries rather than source. Regards, Myron.
Jun 07 2007
parent reply "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"Myron Alexander" <someone somewhere.com> wrote in message 
news:f49mt6$1t6d$1 digitalmars.com...
 In D, the import statement imports a compiled module, not source.

 ...

 In one sentence, modules provide the functionality of #include (and so 
 much more) but with "special" binaries rather than source.
Not exactly. When you import a module, it will only ever look for a source file (.d or .di). It never looks for compiled modules. Once it finds a source file, it will lex it, parse it, and do enough semantic analysis to extract the symbol table, which can then be used from the current module.
Jun 07 2007
parent reply Myron Alexander <someone somewhere.com> writes:
Jarrett Billingsley wrote:
 "Myron Alexander" <someone somewhere.com> wrote in message 
 news:f49mt6$1t6d$1 digitalmars.com...
 In D, the import statement imports a compiled module, not source.

 ...

 In one sentence, modules provide the functionality of #include (and so 
 much more) but with "special" binaries rather than source.
Not exactly. When you import a module, it will only ever look for a source file (.d or .di). It never looks for compiled modules. Once it finds a source file, it will lex it, parse it, and do enough semantic analysis to extract the symbol table, which can then be used from the current module.
Thanks for the clarification, I misunderstood how modules work. Please correct me if the following is incorrect: Modules are not included in the current source as part of the source (like #include does) but the module (.d) or module interface (.di) is parsed for declarations and module constructor/destructor/static methods. Thanks, Myron.
Jun 07 2007
parent reply "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"Myron Alexander" <someone somewhere.com> wrote in message 
news:f4a78d$qhk$1 digitalmars.com...
 Please correct me if the following is incorrect:

 Modules are not included in the current source as part of the source (like 
 #include does) but the module (.d) or module interface (.di) is parsed for 
 declarations and module constructor/destructor/static methods.
Right :)
Jun 07 2007
parent Myron Alexander <someone somewhere.com> writes:
Thanks
Jun 08 2007
prev sibling parent BCS <ao pathlink.com> writes:
Reply to Tibi,

 Can someone please tell me a few words about separate compilation in
 D. A small example would be nice, if I`m not asking too much.
 
 And one more thing, I haven`t understood very well what import does,
 is it similar to the #include statement from C++ or is it somewhat
 different?
 
to compile a file and not link it use -c dmd -c myfile.d to link several object files uses your linker on linux gcc a.o b.o c.d -<needed flags> // the flags can be found by calling dmd with a hello world and watching the output to stdout on win32 it is about the same but the linker you will need to use in in dm/bin/link.exe and I don't remember how to get the args. OTOH if you call DMD with only object files, in win32 or linux it will link them
Jun 07 2007