DIFFEERENCE btw C and C++???

I have tested two little programs written using C and C++
C source code:
1
2
3
#include <stdio.h>
#include <string.h>
int main(){}


C++ source code:
1
2
3
4
#include <iostream>
#include <string>
using namespace std;
int main(){}


two empty programs. But when I compared the sizes of both exe files, the result was:
program written using C: 19Kb
program written using C++: 571 Kb
Can anyone explain me why it is so???
Your C++ program almost certainly has the C++ runtime (plus the C runtime) library in it.
Make sure to strip the resulting executables of debug information also.

If you are using the GCC, it tends to produce a little bit larger code also.

Further, if you want the smallest executable, make sure to dynamically link with your libraries. That is the default on Unix/Linux systems, but not on Windows.
Also, you are calling two completely different sub-libraries when you're including stdio and cstring vs iostream and string, and I have a feeling that makes a difference.

EDIT: Okay, maybe it doesn't. Silly thing, though...

-Albatross
Last edited on
http://www.mingw.org/wiki/Large_executables

MinGW can generate C++ binaries comparable in size to C binaries, too, but it takes some convincing.

EDIT: Oh, and statically linking things makes programs generally easier to distribute.
Last edited on
Topic archived. No new replies allowed.