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>
usingnamespace 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???
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...