Brett W. McCoy wrote: > On 1/29/07, Nuno Berneaud <[EMAIL PROTECTED]> wrote: > >>> BTW, found this in Bjarne's C++ FAQ: >>> Why is the code generated for the "Hello world" program ten times >>> larger for C++ than for C? >>> It isn't on my machine, and it shouldn't be on yours. I have even >>> seen the C++ version of the "hello world" program smaller than the C >>> version. When I recently (2004) tested using gcc -o2 on a Unix, the >>> two versions (iostreams and stdio) yielded identical sizes. There is >>> no language reason why the one version should be larger than the >>> other. It is all an issue on how the implementor organized the >>> libraries. If one version is significantly larger than the other, >>> report the problem to the implementor of the larger. >> I've tried the Bjarne's "hello world" example, too, and was surprised to see >> the >> executable was almost 4MB! 5 lines of code, a couple includes, isn't it a bit >> too much? > > 4MB?!??!?!?! What compiler? > > I just tried with CygWin, using -o2 with gcc 3.4.4 and got: > > $ ls -l hello* > -rwxrwxrwx 1 Bones None 86 Jan 29 20:26 hello_c.c* > -rwxr-xr-x 1 Bones None 8.7K Jan 29 20:29 hello_c.exe* > -rwxrwxrwx 1 Bones None 113 Jan 29 20:31 hello_cpp.cpp* > -rwxr-xr-x 1 Bones None 466K Jan 29 20:32 hello_cpp.exe* > > But on Linux, using gcc 3.3.6, I got > > [EMAIL PROTECTED] ~ $ ls -l hello* > -rwxr-xr-x 1 bmccoy users 6083 Jan 30 01:48 hello_c > -rwxr-xr-x 1 bmccoy users 86 Jan 30 01:48 hello_c.c > -rwxr-xr-x 1 bmccoy users 7834 Jan 30 01:48 hello_cpp > -rwxr-xr-x 1 bmccoy users 113 Jan 30 01:48 hello_cpp.cpp > > Why does CygWin produce such a large C++ binaries? > > -- Brett
Brett, have you taken the EXE apart? Any number of things could be happening: Static linking, massive (and unnecessary) string and numeric mapping tables getting compiled in and not removed even though the functions using those tables are never used, symbol table inclusion, etc. You'd have to analyze the file with PE tools (tools that take apart PE files) to figure out what's being included that is causing the size difference. Also, PE files are probably naturally larger than the ELF equivalent (you can store a lot of junk in an EXE such as bitmap resources). -- Thomas Hruska CubicleSoft President Ph: 517-803-4197 *NEW* VerifyMyPC 2.0 Change tracking and management tool. Reduce tech. support times from 2 hours to 5 minutes. Free for personal use, $10 otherwise. http://www.CubicleSoft.com/VerifyMyPC/
