When I compile this code, I get a file size of 455.50KB. When I comment out lines 9 and 10, my file size stays about the same. If I comment out line 8, my file size goes down to 5.50KB.
Why does declaring ifstream file;
add an extra 450KB to the file, and how can I shrink it? I have no compiler flags set. I'm using Code::Blocks 10.05 with MinGW.
(Yes, I am aware the code doesn't do anything useful. It's just a test for now)
Using C++ streams in MinGW has a relatively large size overhead.
Streams are template classes, and template classes and functions don't generate any code if they're not used. That's why not declaring 'file' leaves you with a much smaller binary.
I had this very some problem the other day. Your options are:
1. Use the -s compiler option. This will reduce the file size by about 2/5.
2. Link dynamically. I don't know if this is possible with MinGW, but it's the default with VC++. Linking dynamically has certain drawbacks, though.
3. Don't use C++ headers. This is what I did. Instead, use C headers.
C++ is a great language, but some implementations don't behave nicely with minuscule programs.