www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Why exe size change if import entire std or just writeln?

reply Marcone <marcone email.com> writes:
import std.stdio : writeln;

void main(){
	writeln("Bom dia");
}


Size exe file: 258 KB

--------------------------------------------------------------

import std;

void main(){
	writeln("Bom dia");
}

Size exe file: 595 KB



If dependencies are resolved at compile time, why does the 
compiler include extra stuff?
Mar 23 2022
next sibling parent "H. S. Teoh" <hsteoh quickfur.ath.cx> writes:
On Thu, Mar 24, 2022 at 01:49:30AM +0000, Marcone via Digitalmars-d-learn wrote:
 import std.stdio : writeln;
 
 void main(){
 	writeln("Bom dia");
 }
 
 
 Size exe file: 258 KB
 
 --------------------------------------------------------------
 
 import std;
 
 void main(){
 	writeln("Bom dia");
 }
 
 Size exe file: 595 KB
 
 
 
 If dependencies are resolved at compile time, why does the compiler
 include extra stuff?
Did you compile with LTO? If not, the exe may carry extra baggage, since the linker may not have tried to shed excess baggage. T -- My father told me I wasn't at all afraid of hard work. I could lie down right next to it and go to sleep. -- Walter Bright
Mar 23 2022
prev sibling parent Salih Dincer <salihdb hotmail.com> writes:
On Thursday, 24 March 2022 at 01:49:30 UTC, Marcone wrote:
 If dependencies are resolved at compile time, why does the 
 compiler include extra stuff?
You are right! Test results on linux: ```d //import std.stdio : writefln;/* version = 1; import core.stdc.stdio : printf;//*/ void main() { string hello = "hello"; version(1) { printf("%s world\n", hello.ptr);// 6464 bytes with strip } else hello.writefln!"%s World!"; // 196KB with strip } /* * ldc2 -O hello.d -release */ ```
Mar 24 2022