Ok when I use gcc (all th time) the program it makes in c++ with debug on is around a megabyte when off it is around half a megabyte when working with c with debug on it around 50 k with it off it's at about25 k this doesn't seem to depend on how much is in the program (none of mine are large) so what compiler makes he smallest programs?

I have never used a flag... What does it(-O) do? I do know what flags are. Though.

All the -O flags are related to optimizations. There are -O0 through -O3 going up in speed optimizations. There is also -Os which tries to minimize the size of the output file.

Ok I just noticed that code blocks turned all these on for me automatically... So back to the compiler question. PS I have no memory problems I just want to know how because Ill probably need it if I start makeing big programs.

Oh, well you may want to specify only the -Os flag. But anyway, there aren't that many compilers that are as good as GCC, and I couldn't name one that produces smaller executables (besides TCC, but that is only for C, not C++). If you are worried about the size of the actual executable file then you can try to modularize the program, e.g. by using shared libraries or putting your data in external files.

Well. My best guess to explain the difference in size is that C++ has constructs that are a lot more feature-rich than their C counter-parts. Taking a simple "Hello World" program example, in C it will just involve using the printf() function, while the C++ version would entail constructing the std::cout object and a lot of its underlying code (iostream code has several levels of classes and buffers). So, basically, basic features of the standard library in C++ would just amount to quite a bit more code than the C counterparts. This is not so relevant because it will not grow with the size of your code (it is like a starting size). But, of course, C++ code will tend to create larger binaries (and the -Os can certainly help to reduce that if it is really a concern), by how much is a question I cannot answer (it also depends highly on your coding style).

As for compiler-vendors and how they compare in sizes of binaries, I can't tell specifically, but GCC is amongst the best compilers all-around, it is only beaten by the Intel compilers (ICC) but these are quite expensive (thousands of dollars).

Edited 5 Years Ago by mike_2000_17: n/a

Ok one last question. Why does it always land at the SAME size every compileation... I went through every program I made in release and debug and all of the debugs where the same size and all the releases are the same size. This happens down to the byte level... Why?

>>all of the debugs where the same size and all the releases are the same size.

As I said, most of the size of those binaries are probably due to a fixed amount of basic code that the compiler puts in for the C/C++ standard libraries. The part that is compiled from your code is probably very small in comparison. Compilers probably also do a certain amount of padding (inserting blank memory to better align the different parts of the code) and your code probably doesn't exceed that padding, and thus, you get the exact same size every time.

This question has already been answered. Start a new discussion instead.