3 ms·
You can actually get Hello World down to 1.5K in MSVC with the right compiler switches. First the code to say hello: const char \*const str = "Hello World!\
by Dwedit 4y ago
You can actually get Hello World down to 1.5K in MSVC with the right compiler switches.
First the code to say hello:
const char \*const str = "Hello World!\n";
HANDLE standardOutput = GetStdHandle(STD_OUTPUT_HANDLE);
WriteFile(standardOutput, str, strlen(str), NULL, NULL);
Then the compiler switches:
/merge:.rdata=.text cuts out an entire section 0.5K
/nocoffgrpinfo cuts out about 256 bytes from your .text section
/emittoolversioninfo:no is supposed to omit the RICH header, but doesn't seem to work anymore.
/stub:stub.bin will let you replace the default DOS EXE stub with something smaller. Using a 64 byte file will get the EXE header and PE header to fit in the first 512 bytes (when combined with merging the .rdata and .text sections)
Set "Entry Point" to main. This completely bypasses the C standard library and CRT, none of that gets initialized or called.
Then you end up with an EXE containing 3 sections: The EXE header (512 bytes), the .text section (512 bytes, but only 141 bytes actually used in there), and the .idata section (512 bytes, for importing DLLs, only 41 bytes actually used)