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++98orc++03forISO C++ 1998 with amendmentsstandardgnu++98orgnu++03forISO C++ 1998 with amendments and GNU extensionsstandardc++11forISO C++ 2011 with amendmentsstandardgnu++11forISO C++ 2011 with amendments and GNU extensionsstandardc++14forISO C++ 2014 with amendmentsstandardgnu++14forISO C++ 2014 with amendments and GNU extensionsstandardc++17forISO C++ 2017 with amendmentsstandardgnu++17forISO C++ 2017 with amendments and GNU extensionsstandardc++20forISO C++ 2020 DISstandardgnu++20forISO C++ 2020 DIS with GNU extensionsstandardc89,c90, oriso9899:1990forISO C 1990standardiso9899:199409forISO C 1990 with amendment 1standardgnu89orgnu90forISO C 1990 with GNU extensionsstandardc99oriso9899:1999forISO C 1999standardgnu99forISO C 1999 with GNU extensionsstandardc11oriso9899:2011forISO C 2011standardgnu11forISO C 2011 with GNU extensionsstandardc17,iso9899:2017,c18, oriso9899:2018forISO C 2017standardgnu17orgnu18forISO C 2017 with GNU extensionsstandardc2xforWorking Draft for ISO C2xstandardgnu2xforWorking Draft for ISO C2x with GNU extensionsstandard
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.