This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

arm-none-eabi-gcc default parameters

how to know exactly which parameters are enabled/disabled by default for arm-none-eabi-gcc?

I have the doubt thinking about the parameter `-fshort-enum`.

Try to compile this example (main.c):

#include <stdio.h>

typedef enum
{
	A,
	B,
	C,
	
	max_e,
} e_t;

/* static assert for detect size of e_t @compile time using DIM symbol */
_Static_assert(DIM == sizeof(e_t), "sizeof do not match");

void f(e_t p)
{
	if(p<0 || p>=max_e){
		printf("out of range %d\n", p);
		return;
	}
	printf("p %d\n", p);
}

int main(void)
{
	f(0);
	f(1);
	f(5);
	f(-1);
	return 0;
}

First I used gcc on my ubuntu 18.04 (with '-DDIM=x -std=gnu11 -Wall -Wextra' parameters):

max@resfw04:~/progs/test_enum_signed$ gcc --version
gcc (Ubuntu 7.4.0-1ubuntu1~18.04.1) 7.4.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

max@resfw04:~/progs/test_enum_signed$ gcc -DDIM=1 -std=gnu11 -Wall -Wextra main.c -c -o main.o
main.c:12:1: error: static assertion failed: "sizeof do not match"
max@resfw04:~/progs/test_enum_signed$ gcc -DDIM=2 -std=gnu11 -Wall -Wextra main.c -c -o main.o
main.c:12:1: error: static assertion failed: "sizeof do not match"
max@resfw04:~/progs/test_enum_signed$ gcc -DDIM=4 -std=gnu11 -Wall -Wextra main.c -c -o main.o
max@resfw04:~/progs/test_enum_signed$

As you can see I have gcc 7.4.0 on my machine, and it seems that the default is '-fno-short-enum', in fact the build fails with DIM other than 4.

The I tried to compile with arm toolchain (same parameters):

max@resfw04:~/progs/test_enum_signed$ arm-none-eabi-gcc --version
arm-none-eabi-gcc (GNU Tools for Arm Embedded Processors 7-2018-q2-update) 7.3.1 20180622 (release) [ARM/embedded-7-branch revision 261907]
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

max@resfw04:~/progs/test_enum_signed$ arm-none-eabi-gcc -DDIM=1 -std=gnu11 -Wall -Wextra main.c -c -o main.o
main.c: In function 'f':
main.c:16:6: warning: comparison is always false due to limited range of data type [-Wtype-limits]
  if(p<0 || p>=max_e){
      ^
max@resfw04:~/progs/test_enum_signed$ arm-none-eabi-gcc -DDIM=2 -std=gnu11 -Wall -Wextra main.c -c -o main.o
main.c:12:1: error: static assertion failed: "sizeof do not match"
 _Static_assert(DIM == sizeof(e_t), "sizeof do not match");
 ^~~~~~~~~~~~~~
main.c: In function 'f':
main.c:16:6: warning: comparison is always false due to limited range of data type [-Wtype-limits]
  if(p<0 || p>=max_e){
      ^
max@resfw04:~/progs/test_enum_signed$ arm-none-eabi-gcc -DDIM=4 -std=gnu11 -Wall -Wextra main.c -c -o main.o
main.c:12:1: error: static assertion failed: "sizeof do not match"
 _Static_assert(DIM == sizeof(e_t), "sizeof do not match");
 ^~~~~~~~~~~~~~
main.c: In function 'f':
main.c:16:6: warning: comparison is always false due to limited range of data type [-Wtype-limits]
  if(p<0 || p>=max_e){
      ^
max@resfw04:~/progs/test_enum_signed$ 

In this case it seems that is enabled '-fshort-enum' by default, in fact the build fails with DIM other than 1, and I have also a warning.

So I must deduce that the default of the two gcc's is different, I guess for other parameters, maybe even many.

Where can I find the default parameters for arm-none-eabi-gcc? Is it a document distributed with the toolchain or online? Or should I look at the sources? And in the latter case exactly where?

best regards

Max