Last active
May 18, 2023 12:33
-
-
Save pmttavara/2ec86e1a0e91e703922d34c40fa69253 to your computer and use it in GitHub Desktop.
Better assert() for Windows - public domain
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 good_assert /* Better assert() for Windows - public domain */ | |
#ifdef _WIN32 | |
#ifdef __cplusplus | |
extern "C" { | |
#endif | |
#ifndef _WINDOWS_ | |
__declspec(dllimport) int __stdcall ExitProcess(unsigned int a); | |
__declspec(dllimport) int __stdcall MessageBoxA(void *a, const char *b, | |
const char *c, unsigned int d); | |
#endif /* _WINDOWS_ */ | |
static int good_assert_(const char *s) { | |
int x = MessageBoxA(0, s, "Assertion Failed", 0x1012); | |
if (x == 3) ExitProcess(1); | |
return x == 4; | |
} | |
#define good_assert_STR_(LINE) #LINE | |
#define good_assert_STR(LINE) good_assert_STR_(LINE) | |
#ifdef NDEBUG | |
#define good_assert(ignore) ((void)0) | |
#else | |
#define good_assert(e) ((e) || good_assert_("At " __FILE__ ":" good_assert_STR \ | |
(__LINE__) ":\n\n" #e "\n\nPress Retry to debug.") && (__debugbreak(), 0)) | |
#endif | |
#ifdef __cplusplus | |
} | |
#endif | |
#else | |
#include <assert.h> | |
#define good_assert assert | |
#endif /* _WIN32 */ | |
#endif /* good_assert */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment