I need an extremely optimized compiler that gives a very small output file. I'm limited extremely on space where I'm working on my projects currently. A simple executable like:
#include <iostream>
#include <string>
#include <sstream>
int main(int argc, char ** argv)
{
std::cout << "Please enter the grade you recieved in programming: ";
int grade;
std::string input;
while(true)
{
getline(std::cin,input); //Recieve grade from user.
std::stringstream temp(input);
if (temp >> grade)
{
if (grade >= 90 && grade <= 100)
std::cout << "Congratulations! You made an A!";
elseif (grade >= 80 && grade < 90)
std::cout << "Congratulations! Your above average with a B!";
elseif (grade >= 70 && grade < 80)
std::cout << "Boo! Your an average Joe with a C!";
elseif (grade >= 60 && grade < 70)
std::cout << "Boo! You fail at life with a D!";
elseif (grade >= 0 && grade < 60)
std::cout << "Failure! Try better slob! F!";
else { std::cout << "Please enter a valid grading number: "; continue; }
std::cout << std::endl << grade;
break;
}
else std::cout << "Invalid number, please try again: ";
}
getchar();
}
...compiles to a little bit over a half megabyte. In C, the executable would be around 50 KB. I've tried MinGW but it's known for giving a big as hell executable. I'm trying as hard as I can to avoid VC++. Borland C++ is outdated. And I can't use the DM ++ compiler on school premises although that hasn't stopped me before. Any suggestions? I wish TinyC supported C++. T.T
What's wrong with VC++? Why would you avoid it on purpose? Anyway, doesn't any good compiler provide optimization settings? The moment you start using things from the stream libraries your executable grows. I'm sorry to say that I do not believe that you can shrink a c++ program like that down to 50KB.
You'd have to rewrite the program to shrink it down. Manually parse the strings and use character arrays instead of std::string. In other words, write a c program and the executable will be much smaller. That's the tradeoff between C and C++ I'm afraid.
I can't get it below 250 KiB with MinGW 3.x (4.x gives even bigger executables).
VC++ can get it to 11 KiB with dynamic linking, and to ~150 KiB with static linking.
I couldn't get it below 316kb myself using the integrity compiler I have. I don't see any such option for dynamic vs static linking of run time libraries. I have to email tech support for this compiler to find out why.