Question:
why is the size of file greater in c++ than c after compilation?
crazy4fun
2010-05-20 04:31:49 UTC
Do anyone have idea about this, why the size of the file is greater in c++ than c after the compilation(only not executed)?
Four answers:
tbshmkr
2010-05-20 05:28:12 UTC
You did not say which compilers/OS you were using, so a specific explanation can not be given.

=

You did not say (show) the source code. of the two files.

- For small and even medium sized programs the runtime library often accounts for a large part of the executable size.

-

The quality of the linker and the linker settings may have some impact on the executable size as well.

- Optimization settings of the compiler make a (small) difference too.

-

One thing that may explain the difference you are seeing is that one compiler stores the debug information in the executable itself while the other stores the debug information in a separate file

- You are more likely to get more sensible numbers if you do an optimized build without debug information with both compilers.
suresh k
2010-05-20 12:32:57 UTC
probably you are asking the "archive libraries" concept...



reference:

1)static libraries.

2)Dynamically linked shared object libraries.



when you compile a code in c or in c++, it groups multiple compiled object code files into a single file known as a library.

The C standard libraries and C++ STL(Standard Template Library) are examples of shared components which can be linked with your code.



since C++ may include more of these shared libraries than C does.. C++ files are greater in size than C files after compilation :)
?
2010-05-20 11:43:01 UTC
Probably because C++ has more to it than C. Therefore most likely compiles differently and adds more junk in.
2010-05-20 12:35:14 UTC
The library routines of the compilers you're using determine that.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...