Addition of -std=gnu++11 and -std=gnu11 compile flags

Post here first, or if you can't find a relevant section!
User avatar
Rick Kimball
Posts: 1067
Joined: Tue Apr 28, 2015 1:26 am
Location: Eastern NC, US
Contact:

Re: Addition of -std=gnu++11 and -std=gnu11 compile flags

Post by Rick Kimball » Fri Dec 08, 2017 8:56 pm

Rick Kimball wrote:
Wed Mar 08, 2017 3:22 pm
I like nano.specs .. however most here are probably going to be surprised that printf functions that use %f will silently display nothing .. Just wanted people to be aware and not freak out.
I noticed that the size of our code just seems to be ever expanding. I was trying out someones test example that used sprintf and floats and its resulting compiled size was ~36k for a bluepill. This seems excessive. I did some more digging around and came across this post.

http://www.openstm32.org/forumthread2108#threadId2999

Basically the author suggests using '-specs=nosys.specs -specs=nano.specs -u _printf_float' specifically in that order. The intent was to use most of the nano.specs library but revert back to the normal printf floating point behavior. I gave it a try by modifying my board setting:
$ git diff
diff --git a/STM32F1/boards.txt b/STM32F1/boards.txt
index 49c1293..029aecf 100644
--- a/STM32F1/boards.txt
+++ b/STM32F1/boards.txt
@@ -410,7 +410,8 @@ genericSTM32F103C.menu.cpu_speed.speed_128mhz.build.f_cpu=128000000L
#-- Optimizations
genericSTM32F103C.menu.opt.osstd=Smallest (default)
genericSTM32F103C.menu.opt.osstd.build.flags.optimize=-Os
-genericSTM32F103C.menu.opt.osstd.build.flags.ldspecs=
+genericSTM32F103C.menu.opt.osstd.build.flags.ldspecs=-specs=nosys.specs -specs=nano.specs -u _printf_float
genericSTM32F103C.menu.opt.oslto=Smallest Code with LTO
genericSTM32F103C.menu.opt.oslto.build.flags.optimize=-Os -flto
genericSTM32F103C.menu.opt.oslto.build.flags.ldspecs=-flto
I went from ~36k to ~25k .. and floating point was still working with sprintf.

This might be something to try if you are annoyed by the ever expanding flash waistline.
-rick

stevestrong
Posts: 1948
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany
Contact:

Re: Addition of -std=gnu++11 and -std=gnu11 compile flags

Post by stevestrong » Fri Dec 08, 2017 9:15 pm

I just tried Rick's ld.specs with a modified version of RTC lib, using sprintf, went down from ~36k to ~18k, sprintf working fine.

+5 :P

lacklustrlabs
Posts: 12
Joined: Fri May 05, 2017 12:35 pm

Re: Addition of -std=gnu++11 and -std=gnu11 compile flags

Post by lacklustrlabs » Mon Dec 11, 2017 10:46 am

So what's the word on backward compability with c++98?
Do we need to litter our new code with #if __cplusplus >= 201103L tests?

I'd prefer if C++11 (or higher) was a hard requirement. That would make new code so much cleaner and easier to test.
Maybe it is required already...

Post Reply