hello friends! new(ish)!
GCC
GCC stands for GNU Compiler Collection. It is a compiler system licensed under the GPL and is part of the GNU toolchain. Originally, it stood for GNU C Compiler because it could only compile C, but it has since gained support for various languages.
GCC is ubiquitous in GNU/Linux systems and is very often used to compile the Linux kernel. It is one of the most mature compiler suites available today.
Supported languages
Command Line Arguments
These options are broadly shared with clang, though the particular effect may vary.
Compilation Mode
-E: preprocessing only
-S: compile to assembly
-c: compile to object file
Optimization
-O0: optimization off. Default
-O2: strong optimization. Recommended for production code
-O3: potentially better optimization than -O2. Also potentially worse. Not recommended for production code.
-Os: optimize to minimize space, not minimize runtime. Sometimes has the knockon effect of speeding up code as well
Warnings
-Wall: enable all warnings. Highly recommended
-Werror: fail compilation if there are any warnings. Highly recommended
Options
-fsanitize=undefined: UBSan. Good for sussing out undefined behaviour errors
-fno-strict-aliasing: famously used by the linux kernel. Another good way of dealing with undefined behaviour errors
Machine Options
-march=native: gotta go fast. Quick way to enable vectorization. Resultant binaries aren't as portable
C Extensions
Most GCC extensions have also been implemented in clang, and have that degree of portability. However, they are less likely to be implemented by MSVC, nor more marginal compilers. Hence code that aims for broad portability should avoid them.
Block Expressions
({printf("example statement\n"); "the last statement is the value of the expression"; })
Especially useful for implementing macros
Nested functions
void f1(){ void f2(); f2(); }
Note: not implemented by clang. Has a number of other issues, so probably best avoided.