blob: ad07dab9793649f679c9749204ab02c879fb5151 (
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
|
+++
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
```c
#ifdef _WIN32
// Windows
#endif
#ifdef __APPLE__
// Apple - flags for specific devices defined in <TargetConditionals.h>
#endif
#ifdef __linux__
// Linux
#endif
```
### Compiler detection
```c
#ifdef __GNUC__
// GCC
#endif
#ifdef __clang__
// clang
#endif
#ifdef _MSC_VER
// Visual C
#endif
```
### Architecture detection
```c
#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
```c
// Push/pop warning state
#pragma GCC diagnostic push
#pragma GCC diagnostic pop
// Disable a warning
#pragma GCC diagnostic ignored "-Wunused-variable"
```
### MSVC pragmas
```c
// 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)
|