3 ms·
You're comparing C+StdLib vs. Rust without StdLib. Disable stdlib for C version and use the following program: #include <windows.h> int _start() { const
by slezyr 6y ago
You're comparing C+StdLib vs. Rust without StdLib. Disable stdlib for C version and use the following program:
#include <windows.h>
int _start()
{
const char str[] = "Hello world!\n";
HANDLE stdout = GetStdHandle(STD_OUTPUT_HANDLE);
DWORD written;
WriteFile(stdout, str, sizeof(str), &written, NULL);
ExitProcess(12);
return 0;
}
https://stackoverflow.com/a/42536990 https://stackoverflow.com/a/42536990
Which is similar to what the Rust program does. The result should be significantly less than 1k
- zamadatix 6y agoI think the thing being measured by GP is "easiest way to get to the 1kb mentioned in the title" not "most complicated way to get as small as possible".
- ChrisSD 6y agoI tried your program with MSVC using the following command: cl small2.c /MD /link /entry:_start /subsystem:CONSOLE kernel32.lib It's 5kb.
- slezyr 6y agoIf I remember correctly you need a /nodefaultlib flag to disable stdlibs https://docs.microsoft.com/en-us/cpp/build/reference/nodefaultlib-ignore-libraries?redirectedfrom=MSDN&view=msvc-160 https://docs.microsoft.com/en-us/cpp/build/reference/nodefau...
- ChrisSD 6y agoOk, I've just tried that but I also needed to add `/force` otherwise it complained about missing symbols. So the full compile line is: cl small2.c /link /force /nodefaultlib /entry:_start /subsystem:CONSOLE kernel32.lib This gets it down to 3kb.