Click here to Skip to main content
13,090,730 members (45,751 online)
Rate this:
Please Sign up or sign in to vote.
See more:
why do different compilers output different exec file sizes?
it is just a "hello world" file written in c language on windows platform, i am new to c, exploring many IDEs it gave me different exec file size,
1st: i am wondering why this happens because its the same code, is this normal?
2nd: if it is normal, what is the best compiler to get the smallest exec file size?
Posted 26-Nov-12 19:17pm
Updated 26-Nov-12 19:37pm
Why do you think they should give the same size? Different compilers on the same platform, or different? In all cases, it should not be questionable...
Novi Dev 27-Nov-12 1:45am
i think they should give the same size because it is the same code, anyway i improved my question may you have a second look
You need to understand the difference between different notions of the "code", high-level, object code, CPU instructions. There can also be bytecode, and many other things, which might work in a more complex ways than you might imagine...
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

It's possible to write tons of pages discussing such things as code optimization, storing of the data in the executable image and its different layouts, different trade-off between size of code and performance, numerous examples of different ways to produce CPU instructions out of the same high-level code and their advantages and disadvantages, and a lot more, but the truly reasonable answer will remain the same: those file sizes are different because they don't have to be the same.


Answering two follow-up questions:

1st: same answer; too many reasons to be that way; if you really need to get the feel of it, use some disassembler and look at the CPU-level code; please see:[^].

2nd: it's impossible to define what is "best", because "better" is not defined; well, there are some compilers which clearly compare to others, for example, those which are apparently bad; but most of the compilers cannot compare; moreover, a compiler which make the shorter code does not have to be better; there are many criteria of quality, and the length of the code is the least significant, unless you are talking embedded system with severely limited resources (which are hardly ever used to write "Hello world!" :-)).

Novi Dev 27-Nov-12 1:42am
thank you for your care, i improved my question, may you have a look on it again?
thanks in advance
Answered. Please see my updated answer, after [EDIT]. If it just give you the idea, please consider accepting the answer formally (green button) -- thanks.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

1. Because different compilers will generate different code, and use different run time libraries.
2. In modern computer architecture the size of the executable program is rarely of any importance.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04 | 2.8.170813.1 | Last Updated 27 Nov 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100