www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Should the following program compile?

reply "Andres C. Rodriguez" <acr ai.sri.com> writes:
Should the following program (with no import) compile?  It is not 
compiling for me right now.

   int main(char[][] args) {
       std.stdio.writefln("hello world\n");
       return 0;
   }

Conversely, the program below does compile as expected.

   import std.stdio;

   int main(char[][] args) {
       writefln("hello world\n");
       return 0;
   }

Thanks,

Andres
Nov 10 2004
next sibling parent J C Calvarese <jcc7 cox.net> writes:
Andres C. Rodriguez wrote:
 
 Should the following program (with no import) compile?  It is not 
 compiling for me right now.
 
   int main(char[][] args) {
       std.stdio.writefln("hello world\n");
       return 0;
   }
No, it shouldn't work. The "import" statement isn't optional (except for "object"). Adding "std.stdio." could disambiguate that writefln from another writefln, but it doesn't automatically import the module.
 
 Conversely, the program below does compile as expected.
 
   import std.stdio;
 
   int main(char[][] args) {
       writefln("hello world\n");
       return 0;
   }
Right.
 
 Thanks,
 
 Andres
-- Justin (a/k/a jcc7) http://jcc_7.tripod.com/d/
Nov 10 2004
prev sibling parent Ilya Minkov <minkov cs.tum.edu> writes:
Andres C. Rodriguez schrieb:
 
 Should the following program (with no import) compile?  It is not 
 compiling for me right now.
 
   int main(char[][] args) {
       std.stdio.writefln("hello world\n");
       return 0;
   }
Import statement is requiered. There have been requests to make it optional and import silently when a fully qualified name comes (as in your example), but it was decided against, primarily for the sake of building automation - so that build tools can infer the dependencies without parsing completely, but only search for import, processing out comments and version statements. In Java, where this is common, if a source file changes, you recompile it into the .class bytecode file, and you're done with it - other modules don't embed any dependency on the file. In D, it should provoke all files depending on it - say, the ones that import information relevant to data layout, templates, or in the case of release mode anything at all - become invalid and have to be recmpiled. It is similar to C++. You can import into a dedicated struct to create a sort-of namespace, or you can import locally. Usually ro be used and least problematic is private import the module scope.
 Conversely, the program below does compile as expected.
Of course it does. :) -eye
Nov 11 2004