What do the -f and -m in gcc/clang compiler options stand for - Stack Overflow
command line arguments - What does gcc -E option stand for? - Stack Overflow
why do i need to use gcc -Wall
What are the useful GCC flags for C? - Stack Overflow
Videos
I don't have specific sources that state what 'f' and 'm' mean, but we can infer based on usage patterns found in documentation.
'f' stands for 'flag'.
Flags are on if specified via '-fFLAG' and off via '-fno-FLAG'
ex:
-fpic # flag to set position independent code
-fno-builtin # don't recognize build in functions ...
The technical definition is that 'f' defines "Control the interface conventions used in code generation".
Src: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html (e.g -fpci, when this flag is set)
'm' stands for mode. One general characteristic is that it sometimes has parameters. e.g
-mabi=name #abi mode = name
-mcpu=cpu
Src: https://gcc.gnu.org/onlinedocs/gccint/Standard-Names.html (e.g ... when this mode...)
According to gcc onlinedocs, options of the form -ffoo and -fno-foo stand for machine independent code generation conventions.
Examples: fpic, -fno-pic
-m options stand for machine dependent options.
eg: -mcpu, -march, -matomic
https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options or https://home.cs.colorado.edu/~main/cs1300/doc/gnu/gcc_2.html#SEC43
https://gcc.gnu.org/onlinedocs/gcc/Submodel-Options.html#Submodel-Options or https://home.cs.colorado.edu/~main/cs1300/doc/gnu/gcc_2.html#SEC16
I noticed in a lot of examples of compiling .c files they use
gcc myfile.c -o myfile -Wall
but none of the examples I have seen mention what -Wall does and it seems like it's assumed that everyone knows what that is.
My programs seem to compile the same with or without it. I googled a little for "gcc -Wall" and similar phrases but cant find much info on it. Can someone explain what it does? or point me in the right direction?
Here are mine:
-Wextraand-Wall: essential.-Wfloat-equal: useful because usually testing floating-point numbers for equality is bad.-Wundef: warn if an uninitialized identifier is evaluated in an#ifdirective.-Wshadow: warn whenever a local variable shadows another local variable, parameter or global variable or whenever a built-in function is shadowed.-Wpointer-arith: warn if anything depends upon the size of a function or ofvoid.-Wcast-align: warn whenever a pointer is cast such that the required alignment of the target is increased. For example, warn if achar *is cast to anint *on machines where integers can only be accessed at two- or four-byte boundaries.-Wstrict-prototypes: warn if a function is declared or defined without specifying the argument types.-Wstrict-overflow=5: warns about cases where the compiler optimizes based on the assumption that signed overflow does not occur. (The value 5 may be too strict, see the manual page.)-Wwrite-strings: give string constants the typeconst char[length]so that copying the address of one into a non-const char *pointer will get a warning.-Waggregate-return: warn if any functions that return structures or unions are defined or called.-Wcast-qual: warn whenever a pointer is cast to remove a type qualifier from the target type*.-Wswitch-default: warn whenever aswitchstatement does not have adefaultcase*.-Wswitch-enum: warn whenever aswitchstatement has an index of enumerated type and lacks acasefor one or more of the named codes of that enumeration*.-Wconversion: warn for implicit conversions that may alter a value*.-Wunreachable-code: warn if the compiler detects that code will never be executed*.
Those marked * sometimes give too many spurious warnings, so I use them on as-needed basis.
Several of the -f code generation options are interesting:
-fverbose-asmis useful if you're compiling with-Sto examine the assembly output - it adds some informative comments.-finstrument-functionsadds code to call user-supplied profiling functions at every function entry and exit point.--coverageinstruments the branches and calls in the program and creates a coverage notes file, so that when the program is run coverage data is produced that can be formatted by thegcovprogram to help analysing test coverage.-fsanitize={address,thread,undefined}enables the AddressSanitizer, ThreadSanitizer and UndefinedBehaviorSanitizer code sanitizers, respectively. These instrument the program to check for various sorts of errors at runtime.
Previously this answer also mentioned -ftrapv, however this functionality has been superseded by -fsanitize=signed-integer-overflow which is one of the sanitizers enabled by -fsanitize=undefined.