Thread overview | ||||||
---|---|---|---|---|---|---|
|
May 30, 2013 My first D program | ||||
---|---|---|---|---|
| ||||
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!
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?
--
Shriramana Sharma ஶ்ரீரமணஶர்மா श्रीरमणशर्मा
|
May 30, 2013 Re: My first D program | ||||
---|---|---|---|---|
| ||||
Posted in reply to Shriramana Sharma | On Thu, 30 May 2013 12:13:19 +0100, Shriramana Sharma <samjnaa@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/ |
May 30, 2013 Re: My first D program | ||||
---|---|---|---|---|
| ||||
Posted in reply to Regan Heath | Shriramana Sharma: > 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! On Windows32 DMD produces binaries for small programs that are often half the size of binaries generated by similar small C++ programs compiled with G++ (about 300+ against 700+). D has a garbage collector, runtime type introspection (module info, type info, etc), run-time built-in operations on dynamic arrays (concat, append), associative arrays and some of their operations, a sort (but probably the built-in sort and reverse will be deprecated and later removed), exceptions, and more. All that needs space that's absent in the C++ binary. ------------------- Regan Heath: > The D standard library is currently statically linked. This will change shortly/eventually. And then you will need the GC somewhere to run it :-) Both static and dynamic linking have their advantages and disadvantages. I think Go has a storng preference for static linking. Bye, bearophile |
May 31, 2013 Re: My first D program | ||||
---|---|---|---|---|
| ||||
Posted in reply to Regan Heath | Thanks to all those who kindly replied. On Thu, May 30, 2013 at 9:57 PM, Regan Heath <regan@netmail.co.nz> wrote: > > The D standard library is currently statically linked. This will change shortly/eventually. Ah OK -- should have thought of that. So whatever is in libc.so or libstdc++.so doesn't get counted to the size of the C/C++ executables. Likewise we should have a libd.so I suppose. I am all for having shared runtime/stdlib. -- Shriramana Sharma ஶ்ரீரமணஶர்மா श्रीरमणशर्मा |
Copyright © 1999-2021 by the D Language Foundation