Emuforums.com

Go Back   Emuforums.com > General Discussion > Web development / Programming
About Us Register FAQ Members List Calendar Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
Old August 3rd, 2003   #1 (permalink)
Registered User
 
scottlc's Avatar
 
Join Date: Sep 2002
Location: St Andrews, Scotland
Posts: 1,575
C++ Question

I am using Dev-C++ and wondering why

(I removed the pointed brackets from the header names because the browser mistakes it for HTML)

Code:
#include stdio.h

int main()
{
  printf("hello world");
  return 0;
}
Compiles to a 22.6K exe whereas

Code:
#include iostream.h

int main()
{
    cout <<"hello world";
    return 0;
}
Compiles to a 420K exe.
__________________
OS: Arch Linux w/ Kernel 2.6.23.8 + GNOME 2.20.1 - CPU: Intel Pentium M 1.5GHz - Memory: 1280MB DDR PC2700 - Browser: Mozilla Firefox 2.0.0.10
scottlc is offline   Reply With Quote
Old August 3rd, 2003   #2 (permalink)
Registered User
 
Recca's Avatar
 
Join Date: Feb 2002
Location: Where ever fate shall lead me.
Posts: 3,946
Re: C++ Question

Is code 1 (C)
whereas code 2 is (C++).

Im just curios. Since im pretty sure Code 2 is C++.
But i haven't seen code 1 before, but the structure is the same, so i just though it might be C
Recca is offline   Reply With Quote
Old August 3rd, 2003   #3 (permalink)
Registered User
 
scottlc's Avatar
 
Join Date: Sep 2002
Location: St Andrews, Scotland
Posts: 1,575
Re: C++ Question

Yes, but why should the second one be 420K in size? Why does using iostream.h increase the filesize by ~400K?
__________________
OS: Arch Linux w/ Kernel 2.6.23.8 + GNOME 2.20.1 - CPU: Intel Pentium M 1.5GHz - Memory: 1280MB DDR PC2700 - Browser: Mozilla Firefox 2.0.0.10

Last edited by scott_uk5; August 3rd, 2003 at 18:31.
scottlc is offline   Reply With Quote
Old August 3rd, 2003   #4 (permalink)
Puchiko-nyu!
 
kairi00's Avatar
 
Join Date: Jul 2001
Location: 49° 11' N 123° 10' W
Posts: 2,854
Re: C++ Question

The C++ iostream library encapsulates the stream manipulations into 2 basic classes (cin and cout). It abstracts a LOT of the nitty-gritty details (especially in file manipulations) that otherwise you have to deal with when using the C stdio library. With all these abstractions and encapsulation, your life is easier when doing I/O, however, as a tradeoff the compiled filesize is bigger.
__________________
"Not every ejaculation deserves a name."

--- George Carlin
kairi00 is offline   Reply With Quote
Old August 3rd, 2003   #5 (permalink)
Registered User
 
scottlc's Avatar
 
Join Date: Sep 2002
Location: St Andrews, Scotland
Posts: 1,575
Re: C++ Question

But that same program compiled with MetroWerks Codewarrier 6 is only 72K
__________________
OS: Arch Linux w/ Kernel 2.6.23.8 + GNOME 2.20.1 - CPU: Intel Pentium M 1.5GHz - Memory: 1280MB DDR PC2700 - Browser: Mozilla Firefox 2.0.0.10
scottlc is offline   Reply With Quote
Old August 3rd, 2003   #6 (permalink)
Puchiko-nyu!
 
kairi00's Avatar
 
Join Date: Jul 2001
Location: 49° 11' N 123° 10' W
Posts: 2,854
Re: C++ Question

Now that goes beyond my knowledge. It's different compiler behaviours. Different compilers treat and compile different code differently. There may be some optimization flags you can set here and there to tweak the code size. Check the documentation of the compiler(s) you're using to see what types of optimization flags you can use to reduce binary size or do a processor specific optimization, etc.
__________________
"Not every ejaculation deserves a name."

--- George Carlin
kairi00 is offline   Reply With Quote
Old August 3rd, 2003   #7 (permalink)
Registered User
 
scottlc's Avatar
 
Join Date: Sep 2002
Location: St Andrews, Scotland
Posts: 1,575
Re: C++ Question

Dev-C++ uses Mingw. By adding -s argument to the linker and running the EXE through UPX, I was able to get the filesize down to 72K.
__________________
OS: Arch Linux w/ Kernel 2.6.23.8 + GNOME 2.20.1 - CPU: Intel Pentium M 1.5GHz - Memory: 1280MB DDR PC2700 - Browser: Mozilla Firefox 2.0.0.10
scottlc is offline   Reply With Quote
Old August 3rd, 2003   #8 (permalink)
Registered User
 
Recca's Avatar
 
Join Date: Feb 2002
Location: Where ever fate shall lead me.
Posts: 3,946
Re: C++ Question

Where did you get that proggy Scott. Is it freeware or shareware.??
Recca is offline   Reply With Quote
Old August 3rd, 2003   #9 (permalink)
Registered User
 
scottlc's Avatar
 
Join Date: Sep 2002
Location: St Andrews, Scotland
Posts: 1,575
Re: C++ Question

It's open source. That's what the ePSXe team use to compress their EXEs.

http://upx.sourceforge.net/
__________________
OS: Arch Linux w/ Kernel 2.6.23.8 + GNOME 2.20.1 - CPU: Intel Pentium M 1.5GHz - Memory: 1280MB DDR PC2700 - Browser: Mozilla Firefox 2.0.0.10
scottlc is offline   Reply With Quote
Reply

Thread Tools
Display Modes

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 On
Refbacks are On


All times are GMT. The time now is 09:32.

© 2006 - 2008 Emu Forums | About Emu Forums | Legal | A member of the Crowdgather Forum Community


Powered by vBulletin® Version 3.7.0 Release Candidate 3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0 RC5