hello world in D
Adam D. Ruppe
destructionator at gmail.com
Fri May 31 07:48:01 PDT 2013
On Friday, 31 May 2013 at 14:33:48 UTC, khurshid wrote:
> And size of result output file 'hello' equal to 1004.1 Kbyte
Whoa, that's up like several times from the last dmd release....
you can get down to 600 kb or so by not using the flags. Strange,
combining all those flags increases the size by 50%. This is
probably some kind of bug in the new release.
But even without bugs, writeln actually pulls in a lot of code.
If you use printf instead of std.stdio, you'll save about 150 KB
in the executable
import core.stdc.stdio;
void main() {
printf("hello\n");
}
$ dmd test2.d
$ ls -lh test2
-rwxr-xr-x 1 me users 287K 2013-05-31 10:40 test2
$ strip test2
$ ls -lh test2
-rwxr-xr-x 1 me users 195K 2013-05-31 10:41 test2
D programs don't have any dependencies outside the operating
system by default, so they carry the parts of the standard
library they use with them.
That 195K test2 program is mostly druntime's code. If you pull in
std.stdio it also grabs much of the phobos standard library to
support printing, conversion of numbers to strings, and much more.
A 1 MB hello world is just strange though, I'm sure that's some
kind of bug, but the relatively harmless kind, you can still use
it.
More information about the Digitalmars-d
mailing list