There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
access audio avg avg 8 bios blue screen boot bsod computer connection cpu crash css dell desktop dma driver drivers dvd email error excel explorer firefox firefox 3 freeze gimp graphics hard drive hardware hijackthis hjt install internet internet explorer itunes keyboard laptop macro malware monitor motherboard network networking outlook outlook 2003 outlook 2007 outlook express pio problem problems router seo server slow sound sp3 spyware trojan usb video virtumonde virus vista vundo windows windows vista windows xp winxp wireless
Software Development
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Software & Hardware > Software Development >
Why a .exe "Hello World!" in c++ are so big?


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

 
Thread Tools
CVDpr's Avatar
Computer Specs
Senior Member with 234 posts.
 
Join Date: Feb 2005
Location: Puerto Rico
Experience: Intermediate
24-May-2006, 03:31 PM #1
Question Why a .exe "Hello World!" in c++ are so big?
.exe in C++= 464kb

#include <iostream>
using namespace std;
int main()
{
cout<<"Hello World!\n";
system("PAUSE");
}
-------------------------------------------------
.exe in C= 15.4kb

#include <stdio.h>
int main()
{
printf("Hello World!\n");
system("PAUSE");
}
-------------------------------------------------
Why in C++ are bigger, and there is away to reduce it? THX
reneNaduya's Avatar
Computer Specs
Junior Member with 18 posts.
 
Join Date: May 2006
Experience: Intermediate
24-May-2006, 04:33 PM #2
Quote:
#include <stdio.h>
int main()
{
printf("Hello World!\n");
system("PAUSE");
}
That is also a valid C++

By the way, what is your compiler? I think this type or problem is based on compilers. Some compilers have really good code optimization, some don't. Maybe your compiler builds the exe with the C++ run-time libraries and packages, that's why you get huge exe file. Consult your compiler's documentation if that's the case.
CVDpr's Avatar
Computer Specs
Senior Member with 234 posts.
 
Join Date: Feb 2005
Location: Puerto Rico
Experience: Intermediate
24-May-2006, 04:37 PM #3
its the Dev-C++ Ver.4.9.9.2

in the compiler options i select in the linker to strip the executable. and now the file is 260kb
before-464, but i think its still to big....

Last edited by CVDpr : 24-May-2006 04:53 PM.
reneNaduya's Avatar
Computer Specs
Junior Member with 18 posts.
 
Join Date: May 2006
Experience: Intermediate
24-May-2006, 05:02 PM #4
Does it make a difference if you use "using std::cout" instead of "using namespace std"?
CVDpr's Avatar
Computer Specs
Senior Member with 234 posts.
 
Join Date: Feb 2005
Location: Puerto Rico
Experience: Intermediate
24-May-2006, 05:14 PM #5
nop, let me try Visual C++ when i finish to download it..
Shadow2531's Avatar
Distinguished Member with 2,629 posts.
 
Join Date: Apr 2001
25-May-2006, 12:14 AM #6
That's how mingw works.

For example, try:

Code:
#include <iostream>

int main() {

}
Then try:

Code:
int main() {

}
Even though you are not using anything from iostream, stuff from it still gets generated. As your projects get bigger, you'll notice less file size difference between compilers, but with small apps, you notice a big difference and even stripping is not enough to match vc++ for example. If you want to shrink a mingw/gcc-built file down more, use upx to compress it. With upx --best file.exe, you'll get hello world down to 80KB or less.

The alternative is to only include C headers and only use C functions etc., but that defeats the purpose.

There's really not much you can do except use a different compiler or get used to it.
__________________
10 ? "a line as the unending horizon"
20 ? "a curve as the rolling hillside"
30 ? "a point as a distant bird"
40 ? "a ray as the rising sun"
run
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are Off
Refbacks are Off

You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 07:04 PM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.