Skip to content

Instantly share code, notes, and snippets.

@ancientstraits
Created March 7, 2023 18:23
Show Gist options
  • Save ancientstraits/3031e4862fc14de0661696fbccd5a79c to your computer and use it in GitHub Desktop.
Save ancientstraits/3031e4862fc14de0661696fbccd5a79c to your computer and use it in GitHub Desktop.
Simple error-handling utility for C
#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