Archived

This topic is now archived and is closed to further replies.

sevak

To BIG!!

Recommended Posts

/******************************* * CACULATOR *CREATOR:Sevak *DATE OF CREATION: 01/09/03 09:26 *DATE OF REVISON: - *FUNCTIONS: Add,Subtract,Multiply,Divide *REASON CREATED: To practice C++. *USAGE: Basic Math * ********************************/ /**Include Files**/ #include <iostream> #include <stdlib.h> /**Include Files**/ /*****Namespace****/ using namespace std; /*****Namespace****/ /***************Functions*******************/ float Add(float a,float b){return a+b;} float Subtract(float a,float b){return a-b;} float Divide(float a,float b){return a/b;} float Multiply(float a,float b){return a*b;} int Body() {//Begin Body //Body Variables short Choice; float number1,number2,result; //Body Variables while(1) {//Begin While loop 1 cout << "\n\t\t\t 4 function Caculator\n" << "\n1.Add\n2.Subtract\n3.Multiply\n4.Divide\n5.Exit" << "\nPlease choose what you want to do:"; cin >> Choice; switch(Choice) {//Begin Choice switch case 1: cout << "Enter first number to add: "; cin >> number1; cout << "Enter second number to add: "; cin >> number2; result = Add(number1,number2); cout << number1 << " + " << number2 << " = " << result << endl; break; case 2: cout << "Enter first number to Subtract: "; cin >> number1; cout << "Enter second number to Subtract: "; cin >> number2; result = Subtract(number1,number2); cout << number1 << " - " << number2 << " = " << result << endl; break; case 3: cout << "Enter first number to Mulitply: "; cin >> number1; cout << "Enter second number to Multiply: "; cin >> number2; result = Multiply(number1,number2); cout << number1 << " * " << number2 << " = " << result << endl; break; case 4: cout << "Enter first number to Divide: "; cin >> number1; cout << "Enter second number to Divide: "; cin >> number2; result = Divide(number1,number2); cout << number1 << " / " << number2 << " = " << result << endl; break; case 5: return 0; default: cout << "Error: Invalied Command\n"; break; }//End Choice switch }//End While loop 1 }//End Body /***************Functions*******************/ /***************Main*******************/ int main() {//Begin Main Body(); return 0; }//End Main /***************Main*******************/ This simple caculator program takes about 440kb. That seems pretty big. Im using DevC++. Is that normal?O ya and can someone tell me how to create one of those white boxes in a post so i can put my coding in it and it wont look so big.

Share this post


Link to post
Share on other sites
Do you really need #include <stdlib.h> ? that will increase the size a bit, plus it should be cstdlib if it is needed

use [] tags with source and /source in them to add code.



[edited by - quant on September 1, 2003 3:38:55 PM]

Share this post


Link to post
Share on other sites
You need to turn off 'Debug Output Generating' and in the 'Linker Command Line' (orsomething like it) you need to add '-s'. Read the DevCpp FAQs or search the DevCpp forums.


[...] Here it is: [...]

Project Options ->
Parameters ->
Linker ->
Add '-s'.

&

Project Options ->
Compiler ->
1) Linker -> Generate Debugging Information = No
2) Optimization = Yes
3) Optimization -> Best Optimization = Yes

Rebuild your project.




.lick



[edited by - Pipo DeClown on September 1, 2003 3:56:04 PM]

Share this post


Link to post
Share on other sites
#including things you don''t need doesn''t increase code size.
Switching your namespace designations doesn''t increase code size.
And of course he''s using floats. It''s a calculator.

You just need to turn on optimizations and turn off debug output.

I like pie.

Share this post


Link to post
Share on other sites
quote:
Original post by Pipo DeClown
You need to turn off ''Debug Output Generating'' and in the ''Linker Command Line'' (orsomething like it) you need to add ''-s''. Read the DevCpp FAQs or search the DevCpp forums.


Ill second that.
quote:
Original post by Pipo DeClown
Guys it''s about compile/linking optimization, not code optimization.


And that!.

Share this post


Link to post
Share on other sites
It is easily possible to get small EXEs with Dev-C++, you just need to know how. Make sure you have Best Optimisation turned on, and Generate Debugging Information turned off. Then, add -s to the linker command-line paramaters. If that doesn''t give you small enough, get UPX and compress the executable. My tetris clone becomes <50k when using the above techniques.

Share this post


Link to post
Share on other sites
One possible size optimization is to write the module prologue yourself, and not link to the c++ runtime libraries at all.
However, this is relatively difficult compared to other suggestions here.

[edited by - Nik02 on September 2, 2003 10:21:33 AM]

Share this post


Link to post
Share on other sites
quote:
Original post by AikonIV
It is easily possible to get small EXEs with Dev-C++, you just need to know how. Make sure you have Best Optimisation turned on, and Generate Debugging Information turned off. Then, add -s to the linker command-line paramaters. If that doesn''t give you small enough, get UPX and compress the executable. My tetris clone becomes <50k when using the above techniques.


what does the -s option do? I''m looking to do the samething for my programs too but I''m using Borland''s compiler and I was wondering if there''s a similar option under that? I already have debug info turned off and have optimisation set to create smallest possible exe. But the resulting exe file is still well over 100k for a simple console program.





--{You fight like a dairy farmer!}

Share this post


Link to post
Share on other sites