How does GCC behave if it passes conflicting compiler flags?

I know that if you run GCC as such:

gcc -O3 -O2 foo.c 

GCC will use the last optimization flag (in this case, O2 ). However, is this true for all flags? For example, if I execute GCC like this:

 gcc -mno-sse -msse bar.c 

Will it support SSE since this was the last flag, or will this lead to undefined behavior? My initial experiments seem to indicate that it will support SSE, but I'm not sure if this is true for all cases.

+7
source share
1 answer

As a rule, the later parameters in the line redefinition are passed earlier, as you noted in the first example. I personally have not come across any other behavior for the -m or -f flags, but I don't know the specific link in the documentation.

Note that some options do not behave like this:

 $ gcc example.c -DABC -DABC=12 <command-line>: warning: "ABC" redefined <command-line>: warning: this is the location of the previous definition 

Therefore, there must be -UABC to close this warning.

As an aside, clang especially good at solving this problem - it will issue a warning if it ignores a command line parameter that may help you.

+10
source

All Articles