Why are compiled Java class files smaller than C compiled files?

后端 未结 9 1431
被撕碎了的回忆
被撕碎了的回忆 2020-12-16 17:16

I would like to know why the .o file that we get from compiling a .c file that prints \"Hello, World!\" is larger than a Java .class file that also prints \"Hello, World!\"?

9条回答
  •  时光说笑
    2020-12-16 17:43

    Most (as much as 90% for simple functions) of an ELF-format .o file is junk. For a .o file containing a single empty function body, you can expect a size breakdown like:

    • 1% code
    • 9% symbol and relocation table (essential for linking)
    • 90% header overhead, useless version/vendor notes stored by the compiler and/or assembler, etc.

    If you want to see the real size of compiled C code, use the size command.

提交回复
热议问题