Created
March 7, 2023 18:23
-
-
Save ancientstraits/3031e4862fc14de0661696fbccd5a79c to your computer and use it in GitHub Desktop.
Simple error-handling utility for C
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
#ifndef ERROR_H | |
#define ERROR_H | |
#define LOG(...) do { \ | |
fprintf(stderr, "%s:%s():%d: ", __FILE__, __func__, __LINE__); \ | |
fprintf(stderr, __VA_ARGS__); \ | |
fputc('\n', stderr); \ | |
} while(0) | |
#define FAIL(...) do { LOG("Error: " __VA_ARGS__); exit(1); } while(0) | |
#define ASSERT(cond, ...) if (!(cond)) FAIL(__VA_ARGS__) | |
#endif // !ERROR_H |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment