summaryrefslogtreecommitdiff
path: root/content/cheatsheets/c_cpp.md
blob: c1eb6cac04bef9cc2b0a3552af885d6271e97d37 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
+++
title = 'C/C++'
+++

* [Preprocessor Definitions](#preprocessor-definitions)
  * [Platform detection](#platform-detection)
  * [Compiler detection](#compiler-detection)
  * [Architecture detection](#architecture-detection)
  * [GCC pragmas](#gcc-pragmas)
  * [MSVC pragmas](#msvc-pragmas)
* [Standard Headers](#standard-headers)

## Preprocessor Definitions

* [predef wiki](https://github.com/cpredef/predef)

### Platform detection
```
#ifdef _WIN32
  // Windows
#endif

#ifdef __APPLE__
  // Apple - flags for specific devices defined in <TargetConditionals.h>
#endif

#ifdef __linux__
  // Linux
#endif

```

### Compiler detection
```
#ifdef __GNUC__
  // GCC
#endif

#ifdef __clang__
  // clang
#endif

#ifdef _MSC_VER
  // Visual C
#endif
```

### Architecture detection
```
#if (defined(_MSC_VER) && _M_X64) || (defined(__GNUC__) && __amd64__)
  // x86-64
#endif

#if (defined(_MSC_VER) && _M_ARM64) || (defined(__GNUC__) && __aarch64__)
  // arm64
#endif
```

### GCC pragmas
```
// Push/pop warning state
#pragma GCC diagnostic push
#pragma GCC diagnostic pop

// Disable a warning
#pragma GCC diagnostic ignored "-Wunused-variable"
```

### MSVC pragmas
```
// Link against abc.lib
#pragma comment(lib, "abc.lib")

// Push/pop warning state
#pragma warning(push)
#pragma warning(pop)

// Disable a warning
#pragma warning(disable: 4996)
```

## Standard Headers

* [C standard headers](https://en.cppreference.com/w/c/header.html)
* [C++ standard headers](https://en.cppreference.com/w/cpp/header.html)
#
* [assert.h](https://en.cppreference.com/w/c/header/assert.html)
* [complex.h](https://en.cppreference.com/w/c/header/complex.html)
* [ctype.h](https://en.cppreference.com/w/c/header/ctype.html)
* [errno.h](https://en.cppreference.com/w/c/header/errno.html)
* [fenv.h](https://en.cppreference.com/w/c/header/fenv.html)
* [float.h](https://en.cppreference.com/w/c/header/float.html)
* [inttypes.h](https://en.cppreference.com/w/c/header/inttypes.html)
* [iso646.h](https://en.cppreference.com/w/c/header/iso646.html)
* [limits.h](https://en.cppreference.com/w/c/header/limits.html)
* [locale.h](https://en.cppreference.com/w/c/header/locale.html)
* [math.h](https://en.cppreference.com/w/c/header/math.html)
* [setjmp.h](https://en.cppreference.com/w/c/header/setjmp.html)
* [signal.h](https://en.cppreference.com/w/c/header/signal.html)
* [stdalign.h](https://en.cppreference.com/w/c/header/stdalign.html)
* [stdarg.h](https://en.cppreference.com/w/c/header/stdarg.html)
* [stdatomic.h](https://en.cppreference.com/w/c/header/stdatomic.html)
* [stdbit.h](https://en.cppreference.com/w/c/header/stdbit.html)
* [stdbool.h](https://en.cppreference.com/w/c/header/stdbool.html)
* [stdckdint.h](https://en.cppreference.com/w/c/header/stdckdint.html)
* [stddef.h](https://en.cppreference.com/w/c/header/stddef.html)
* [stdint.h](https://en.cppreference.com/w/c/header/stdint.html)
* [stdio.h](https://en.cppreference.com/w/c/header/stdio.html)
* [stdlib.h](https://en.cppreference.com/w/c/header/stdlib.html)
* [stdmchar.h](https://en.cppreference.com/w/c/header/stdmchar.html)
* [stdnoreturn.h](https://en.cppreference.com/w/c/header/stdnoreturn.html)
* [string.h](https://en.cppreference.com/w/c/header/string.html)
* [tgmath.h](https://en.cppreference.com/w/c/header/tgmath.html)
* [threads.h](https://en.cppreference.com/w/c/header/threads.html)
* [time.h](https://en.cppreference.com/w/c/header/time.html)
* [uchar.h](https://en.cppreference.com/w/c/header/uchar.html)
* [wchar.h](https://en.cppreference.com/w/c/header/wchar.html)
* [wctype.h](https://en.cppreference.com/w/c/header/wctype.html)