I'm trying to understand why the output file sizes are significantly different when using a C and a C++ compiler.
I was writing a small hello world program in C and C++, I noticed that in C version, the size of the executable was 93.7KB and in C++, the size of the same hello world program was 1.33MB. I am not sure why that is. I think it may be because C++ has more libraries and namespaces to use so I removed the using namespace std line and simply used std::cout and still the result was the same.
C
#include <stdio.h>
int main()
{
printf("hello world");
return 0;
}
// size 93.7KB
C++
#include <iostream>
int main()
{
std::cout<<"Hello world";
return 0;
}
// size 1.33MB
There doesn't seem to be much difference in the code above. Is there some sort of compiler difference that creates the differing file sizes?
tcc hello.cin http://bellard.org/jslinux/ and inspecta.outinls -ls– rplantiko Jun 26 '14 at 20:03printf(available in C++) will produce a file of similar size to C (for example,-nostdliband-nodefaultlibs. – Gort the Robot Jun 26 '14 at 22:37People tend to assume that for a program to be in C++ it has to use streams and not printf. – Petruza Jul 04 '14 at 02:20