Preprocessor Macros: Difference between revisions
No edit summary |
|||
Line 1: | Line 1: | ||
Some common preprocessor macros | Some common preprocessor macros | ||
==Include Guard== | |||
For most modern compilers (VS Code, gcc, llvm), you can just add a <code>#pragma once</code> at the top. | |||
Note that this is not defined in the standard. | |||
For older compilers: | |||
<syntaxhighlight lang="c"> | |||
#ifndef GRANDPARENT_H | |||
#define GRANDPARENT_H | |||
... contents of grandparent.h | |||
#endif /* !GRANDPARENT_H */ | |||
</syntaxhighlight> | |||
==GLSL== | ==GLSL== |
Revision as of 16:39, 10 May 2020
Some common preprocessor macros
Include Guard
For most modern compilers (VS Code, gcc, llvm), you can just add a #pragma once
at the top.
Note that this is not defined in the standard.
For older compilers:
#ifndef GRANDPARENT_H
#define GRANDPARENT_H
... contents of grandparent.h
#endif /* !GRANDPARENT_H */
GLSL
#define PI 3.141592653589793
#define PI_2 1.5707963267948966
#define DEG2RAD 0.017453292519943295
#define RAD2DEG 57.29577951308232
#define sign(x) (int((x) > 0) - int((x) < 0))
#define imin(x, y) (int(x) * int(int(x) < int(y)) + int(y) * int(int(x) >= int(y)))
#define imax(x, y) (int(x) * int(int(x) > int(y)) + int(y) * int(int(x) <= int(y)))
#define iabs(x) ((x) * int((x) >= 0) - (x) * int((x) < 0))