Reputation: 19526
I wrote this in notepad and then compiled it with lcc-win
, using the command lc hello.c
#include <stdio.h>
int main(void)
{
printf("Hello World\n");
return 0;
}
The resulting exe was 100 KB. Seems kind of huge for a program that just prints Hello World
. Is this normal? Can I reduce the size? 100 KB isn't really an issue these days but it still seems kind of big for what it does. Wouldn't be too bad if every C code I write comes out as a 100 KB exe though.
Upvotes: -1
Views: 428
Reputation: 2025
This is a really simple question, what happens to the lcc-win is the same with the C Compiler Digital Mars, he do not link the exe with dlls containing the functions printf and etc., functions are linked together with EXE, so no requerindo that your computer has the DLLs.
Look, I created a simple Hello World EXE, and I opened hin in Hex Editor.... the printf function is stored in msvcrt.dll, and, the exe don't have this dll in import section...
And, u can found the source definition in this other picture:
Use this style of function definition is more fast then make a dll call....
Upvotes: 0
Reputation: 243
1- Everytime you use the include <>
tag you do make a link with a c library and load it in your programm.
That is also why it is important to include only in the files that actualy need the library functions.
2- On the other part, the binary that you generate is always full of important informations (cf : libelf
or ASM
), headers, steps that needs to be here if you want to programm to be run nicely. This does take space to.
Upvotes: 0