3 ms·
C 8.6kb
by greydius 9y ago
C 8.6kb
- verroq 9y agoSince it's dynamically linked against the runtime library most of the time you need to include how big msvcrt*.dll is.
- MBCook 9y agoThat's an unfair comparison, C doesn't have to bundle an entire interpreter.
- Sindisil 9y agoI like,and use, Java, but the fact that the C hello world requires no "interpreter" (JREs almost always also include one or two JIT compilers, and sometimes no interpreter at all) doesn't make the comparison unfair. In fact, it's the point of the comparison. That said, unless the C binary was statically linked against the CRT, the size of the CRT should also be included (at least on Windows).
- MBCook 9y agoRight but the other things in that list were interpreted languages. A purely compiled language is certainly going to be smaller, but that's slightly apples to oranges.
- deleted 9y ago[deleted]
- userbinator 9y agoYou can get <1KB with the appropriate compiler settings. (I am aware that you can get smaller binaries for other languages by changing the compiler settings too, but I doubt any Java binary can reach that size even with the appropriate settings.)
- tokenizerrr 9y agoAnd what are you linking against, then? I can make a tiny .jar file as long as I get to completely ignore the size of the JDK, much like you're ignoring the size of the libraries you're linking against.
- diek 9y agoActually, funnily enough I just went through and built a semi-freestanding exe to load a jlink'd Java 9 JVM: https://gist.github.com/anonymous/cb6e81a36247563d423f36df19e41f9e https://gist.github.com/anonymous/cb6e81a36247563d423f36df19... The only dependencies this particular ex has is on user32.dll and kernel32.dll so it can call LoadLibrary and GetProcAddress, but if I wasn't interacting with those I could remove those dependencies (though then the exe wouldn't be able to do a whole lot of interesting things). If you look at the file in a hex editor, it's mostly just empty space as it just has four 1k sections with a little bit of data at the start of each.
- smitherfield 9y agoI get 8392 bytes on MacOS. $ echo 'main(){puts("hello, world");}' | cc -fno-PIE -m32 -w -xc - && wc -c a.out 8392 a.out (Other code generation and linker options,[1] GCC instead of Clang, different C/C++ standards, printf(3) or write(2) instead of puts(3) and `void main()` instead of `int main()` all had no effect on the binary size). [1] I tried all the ones listed here, although I didn't try the more exotic methods at the end: http://ptspts.blogspot.com/2013/12/how-to-make-smaller-c-and-c-binaries.html http://ptspts.blogspot.com/2013/12/how-to-make-smaller-c-and...