Page 1 of 1
C++ with GCC: optimizing for size
Posted:
Fri Oct 24, 2014 6:07 pm
by Gravis
Re: C++ with GCC: optimizing for size
Posted:
Sun Oct 26, 2014 5:09 pm
by jeremybennett
Hi Gravis,
All fair comments. C++ is inherently a bigger language than C - it's only just possible on Epiphany. You really are better sticking to C.
I'm not sure how much the inline keyword will do for you. It is advisory only. You are probably better looking at the command line options which control inlining.
Its not at all unusual to get smaller code with -O1 than -Os. -Os is just -O2 with a few optimizations that tend to increase size disabled. There is no GCC equivalent of LLVM's -Oz.
Re: C++ with GCC: optimizing for size
Posted:
Tue Oct 28, 2014 10:08 am
by Gravis
Re: C++ with GCC: optimizing for size
Posted:
Tue Oct 28, 2014 10:16 pm
by notzed
C++ isn't just C with "simpler syntax" (rofl), it's a completely different language. Historical evidence (and indeed, your complaints) suggests it's also a very bulky one.
Re: C++ with GCC: optimizing for size
Posted:
Wed Oct 29, 2014 12:51 pm
by Gravis
Re: C++ with GCC: optimizing for size
Posted:
Wed Oct 29, 2014 4:32 pm
by jeremybennett
Hi notzed, Gravis,
C++ is truly a separate language, it draws its inspiration from two languages, C (of course) and Simula 67. Which is why C++ compilers are not just pre-processors for C.
C++ defines a richer semantics, and implementing that richer semantics will often result in larger code. However if you keep to C like semantics, then on the whole the code size will be the same, as Gravis found out.
The real killer for C++ is that it defines a very large standard libary (the STL). This is where your really big memory growth will happen.
Just one thing to correct from an earlier comment. You can implement an OO design in C, you just need to follow suitable coding discipline. It is quite common to use UML when designing and then implement in C. However C++ provides linguistic structures to make OO coding easier, and these can sometimes prove more efficient when compiled than writing the implementation in C.
HTH,
Jeremy
Re: C++ with GCC: optimizing for size
Posted:
Sun Nov 02, 2014 8:33 pm
by xilman
Re: C++ with GCC: optimizing for size
Posted:
Sun Nov 02, 2014 10:00 pm
by notzed
Re: C++ with GCC: optimizing for size
Posted:
Tue Sep 29, 2015 12:32 pm
by etim
How do you exactly go about reducing the size of the compiled program? The hello-world example () compiles down to a 39KB ELF file. I'm a complete newbie and would love some direction. Thanks!