Last active
February 20, 2020 23:51
-
-
Save nvictor/8b9079f8c59e7eb980894f76cf9b1e26 to your computer and use it in GitHub Desktop.
C Macros
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define LEN(A) (sizeof(A) / sizeof((A)[0])) | |
#define MIN(a, b) ((a) <= (b) ? (a) : (b)) | |
// MAX3, MAX4, etc could be implented in terms of MAX, i.e. MAX((a), MAX((b), (c))) | |
#define MAX(a, b) ((a) >= (b) ? (a) : (b)) | |
// C static assert | |
// if expr is true then evaluates sizeof(char[1]) | |
// if expr is false then evaluates sizeof(char[-1]) which is undefined behavior | |
#define SASSERT(expr) ((void)sizeof(char[1 - 2 * !(expr)])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment