Hi all,

I installed the arm-none-eabi-gcc via brew as proposed in the 1.0.0 mynewt 
documentation for Mac.

So I have the version 4.9.3:

arm-none-eabi-gcc --version
arm-none-eabi-gcc (GNU Tools for ARM Embedded Processors) 4.9.3 20150529 
(release) [ARM/embedded-4_9-branch revision 227977]
Copyright (C) 2014 Free Software Foundation, Inc.


This old compiler uses the gnu89 "C-standard" as default. To check this I just 
included a nonsense for loop in  /apps/blinky/src/main.c:
...
    for(int i=0; i < 3; i++){
        rc += i;
    }
    while (1) {
...

When running a "newt build" the compiler complains and proposes to use the 
option -std=gnu99 

newt build my_blinky_microbit
Building target targets/my_blinky_microbit
Compiling apps/blinky/src/main.c
Error: apps/blinky/src/main.c: In function 'main':
apps/blinky/src/main.c:58:5: error: 'for' loop initial declarations are only 
allowed in C99 or C11 mode
     for(int i=0; i < 3; i++){
     ^
apps/blinky/src/main.c:58:5: note: use option -std=c99, -std=gnu99, -std=c11 or 
-std=gnu11 to compile your code


My question:

Is the mynewt documentation outdated and I should use a newer version of 
arm-none-eabi-gcc, which maybe has gnu99 (or gnu11) as default?

Or are there any side effects which prevents us using the gnu99-Standard?

If gnu99 is not evil in any kind I would prefer it over gnu89, which is now 28 
years old and not even can define a variable in the for-loop.
After many years of java, python and Swift my C is a bit rusty.
So I have read Ben Klemens’ book „21 st Century C“ and he describes a lot of 
advantages in c99, like:
compound literals for arrays and structs, variable-length macros, designated 
initializers, definition of variables not only at the top of a function, ...


I appended the option -std=gnu99 to compiler.flags.default: in 
repos/apache-mynewt-core/compiler/arm-none-eabi-m0/compiler.yml 
and had no obvious negative side-effects with that.

Maybe this -std=gnu99 should be set in the apache-mynewt-core repo or at least 
put as a hint in the documentation about "Installing the Cross Tools for ARM“.

Regards
Alfred

Reply via email to