This document is a WORK IN PROGRESS.
This is just a quick personal cheat sheet: treat its contents with caution!
C C++¶
Table of contents¶
GCC¶
Reference(s)
- https://hackingcpp.com/cpp/cheat_sheets.html
- https://hackingcpp.com/index.html
- https://hackingcpp.com/cpp/community.html
- https://www.youtube.com/watch?v=AMkAKlDI_Gw
- https://learnxinyminutes.com/docs/c++/
- https://stroustrup.com/4th.html
- https://stroustrup.com/Tour.html
- https://gcc.gnu.org/onlinedocs/
- https://gcc.gnu.org/onlinedocs/gcc-11.2.0/gcc/
- https://gcc.gnu.org/onlinedocs/gcc-11.2.0/gcc/Invoking-GCC.html#Invoking-GCC
- https://gcc.gnu.org/onlinedocs/gcc-11.2.0/gcc/C-Dialect-Options.html#C-Dialect-Options
- https://gcc.gnu.org/onlinedocs/gcc-11.2.0/gcc/C_002b_002b-Dialect-Options.html#C_002b_002b-Dialect-Options
- https://www.rapidtables.com/code/linux/gcc.html
When using GNU make With GCC (maybe also with Clang?), some flags can be passed, e.g.:
E.g. some useful options:
- See
-fpermissive
: https://gcc.gnu.org/onlinedocs/gcc-11.2.0/gcc/C_002b_002b-Dialect-Options.html#index-fpermissive - See
-fPIC
: https://wiki.gentoo.org/wiki/Project:AMD64/Fixing_-fPIC_Errors_Guide - See
-Wall
: https://www.rapidtables.com/code/linux/gcc/gcc-wall.html - See
-Wextra
: https://www.rapidtables.com/code/linux/gcc.html - See
-O
: https://www.rapidtables.com/code/linux/gcc/gcc-o.html#optimization
Also, different compiling standards (-std=
) can be used, e.g.:
$ make clean && make CFLAGS="-std=gnu90 -fPIC" CXXFLAGS="-std=c++14 -fpermissive -fPIC"
Here are the available standards:
c++98
orc++03
forISO C++ 1998 with amendments
standardgnu++98
orgnu++03
forISO C++ 1998 with amendments and GNU extensions
standardc++11
forISO C++ 2011 with amendments
standardgnu++11
forISO C++ 2011 with amendments and GNU extensions
standardc++14
forISO C++ 2014 with amendments
standardgnu++14
forISO C++ 2014 with amendments and GNU extensions
standardc++17
forISO C++ 2017 with amendments
standardgnu++17
forISO C++ 2017 with amendments and GNU extensions
standardc++20
forISO C++ 2020 DIS
standardgnu++20
forISO C++ 2020 DIS with GNU extensions
standardc89
,c90
, oriso9899:1990
forISO C 1990
standardiso9899:199409
forISO C 1990 with amendment 1
standardgnu89
orgnu90
forISO C 1990 with GNU extensions
standardc99
oriso9899:1999
forISO C 1999
standardgnu99
forISO C 1999 with GNU extensions
standardc11
oriso9899:2011
forISO C 2011
standardgnu11
forISO C 2011 with GNU extensions
standardc17
,iso9899:2017
,c18
, oriso9899:2018
forISO C 2017
standardgnu17
orgnu18
forISO C 2017 with GNU extensions
standardc2x
forWorking Draft for ISO C2x
standardgnu2x
forWorking Draft for ISO C2x with GNU extensions
standard
Clang¶
Clang is a "LLVM native" C/C++/Objective-C compiler using LLVM as a back end and optimizer. It aims to be GCC compatible yet stricter, offers fast compile times with low memory usage, and has useful error and warning messages for easier compile troubleshooting.
TODO
make CC=/usr/bin/clang CXX=/usr/bin/clang++
cmake . -DCMAKE_CXX_COMPILER=/usr/bin/clang++ -DCMAKE_CC_COMPILER=/usr/bin/clang
gcovr
¶
Code coverage:
- https://gcovr.com/en/stable/guide.html
- https://stackoverflow.com/questions/37957583/how-to-use-gcov-with-cmake
- https://jhbell.com/using-cmake-and-gcov
- ?
$ make clean && make CFLAGS="-fprofile-arcs -ftest-coverage -fPIC -O0"
with GCC only
If this cheat sheet has been useful to you, then please consider leaving a star here.