diff options
| author | 2026-11-08 05:13:29 +0000 | |
|---|---|---|
| committer | 2026-11-08 05:13:29 +0000 | |
| commit | 8bbefe95d25fa2981add4df35bdd9903c91a8e62 (patch) | |
| tree | f45cabee854e1ef7e4b4ce82d4ceced0a47ae2a5 /src/utils.h | |
| download | lab-01-master.tar.gz | |
Diffstat (limited to 'src/utils.h')
| -rw-r--r-- | src/utils.h | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/utils.h b/src/utils.h new file mode 100644 index 0000000..68bb2b5 --- /dev/null +++ b/src/utils.h | |||
| @@ -0,0 +1,26 @@ | |||
| 1 | #ifndef INCLUDED_UTILS_H | ||
| 2 | #define INCLUDED_UTILS_H | ||
| 3 | |||
| 4 | #include <stdlib.h> | ||
| 5 | #include <assert.h> | ||
| 6 | |||
| 7 | #define UNUSED(X) ((void) (X)) | ||
| 8 | #define UNREACHABLE() ASSERT (!"reached the unreachable...") | ||
| 9 | // #define TODO(STR) fprintf (stderr, "%s:%d: warning: TODO "STR"\n", __FILE__, __LINE__) | ||
| 10 | #define TODO(...) | ||
| 11 | |||
| 12 | #define ASSERT assert | ||
| 13 | #define REALLOC realloc | ||
| 14 | #define FREE free | ||
| 15 | |||
| 16 | #define DIE(FMT, ...) \ | ||
| 17 | ({ \ | ||
| 18 | fprintf (stderr, FMT "\n" __VA_OPT__(,) __VA_ARGS__); \ | ||
| 19 | exit (EXIT_FAILURE); \ | ||
| 20 | }) | ||
| 21 | |||
| 22 | #define ARRAY_LEN(array) (sizeof (array)/sizeof (*array)) | ||
| 23 | #define ARRAY_GET(array, index) \ | ||
| 24 | (ASSERT(index >= 0), ASSERT(index < ARRAY_LEN(array)), array[index]) | ||
| 25 | |||
| 26 | #endif | ||
