My first D program

Regan Heath regan at netmail.co.nz
Thu May 30 09:27:45 PDT 2013


On Thu, 30 May 2013 12:13:19 +0100, Shriramana Sharma <samjnaa at gmail.com>  
wrote:

> Hello. I am new to D and come from some intermediate C/C++ plus some
> Python programming background. I currently have DMD 2.062 installed on
> my Kubuntu Raring 64-bit system.
>
> 1. Too big binary output?
>
> OK so I wrote my first Hello World program:
>
> #! /usr/bin/rdmd
> import std.stdio ;
> void main() {
> 	writeln ( "Namaste Prapancha!" ) ;
> }
>
> (so I'm a bit of a Sanskrit geek...) and when I save it as namaste.d,
> do chmod +x and run ./namaste.d, all is fine and I get the output.
>
> However I am somewhat taken aback to see the file size -- 335KiB for a
> simple Hello World? The equivalent C/C++ programs compiled with Clang
> without any -O options produce binaries of less than 10K!

The D standard library is currently statically linked.  This will change  
shortly/eventually.

> 2. No filename freedom?
>
> Next I wanted to go to another example but I like to keep my practice
> files in order, so I rename namaste.d to 01-namaste.d but I get the
> error:
>
> $ dmd 01-namaste.d
> 01-namaste.d: Error: module 01-namaste has non-identifier characters
> in filename, use module declaration instead
>
> Huh? Now my program *name* has to be a valid identifier in the
> language? So I can't have my filename contain a hyphen-minus or start
> with a digit, and only something like e01_namaste.d is permitted. Why
> is this?

As the error says "use module declaration instead".  You need to add a  
"module namaste;" statement to the top of the file 01-namaste.d.  D  
defaults the module name to the filename, but you can specify it when they  
differ.

R

-- 
Using Opera's revolutionary email client: http://www.opera.com/mail/


More information about the Digitalmars-d-learn mailing list