Skip to content

Instantly share code, notes, and snippets.

@m1lkweed
Created February 17, 2023 20:23
Show Gist options
  • Save m1lkweed/88b6dec4cb7c6026e38094a409fcd153 to your computer and use it in GitHub Desktop.
Save m1lkweed/88b6dec4cb7c6026e38094a409fcd153 to your computer and use it in GitHub Desktop.
Macro that tries to check assertions at runtime and compile-time
// (c) M1lkweed, 2022-2023
// GPLv3+
#include <assert.h>
#define ALWAYS_ASSERT(cond, ...) ({static_assert(__builtin_constant_p((cond))?(cond):1,##__VA_ARGS__);assert((cond),##__VA_ARGS__);})
int main(int argc, char**){
ALWAYS_ASSERT(argc > 2);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment