Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++C
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
Edited 26-Nov-12 19:37pm
v2
Comments
Sergey Alexandrovich Kryukov at 27-Nov-12 1:27am
   
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... --SA
Novi Dev at 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
Sergey Alexandrovich Kryukov at 27-Nov-12 2:40am
   
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... --SA
Rate this: bad
good
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.
 
[EDIT]
 
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: http://en.wikipedia.org/wiki/Disassembler[^].
 
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!" Smile | :) ).
 
—SA
  Permalink  
v3
Comments
Novi Dev at 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
Sergey Alexandrovich Kryukov at 27-Nov-12 1:55am
   
Answered. Please see my updated answer, after [EDIT]. If it just give you the idea, please consider accepting the answer formally (green button) -- thanks. --SA
Rate this: bad
good
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.
  Permalink  

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Guruprasad.K.Basavaraju 490
1 Sergey Alexandrovich Kryukov 336
2 OriginalGriff 290
3 Shai Vashdi 284
4 praveen_07 115
0 Sergey Alexandrovich Kryukov 9,185
1 OriginalGriff 5,315
2 Peter Leow 4,040
3 Maciej Los 3,535
4 Abhinav S 3,308


Advertise | Privacy | Mobile
Web01 | 2.8.140415.2 | Last Updated 27 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid