Skip to content
This repository has been archived by the owner on Aug 29, 2024. It is now read-only.

Commit

Permalink
Trapping asserts
Browse files Browse the repository at this point in the history
-> https://nullprogram.com/blog/2022/06/26/ by Chris Wellons (Skeeto)

Called SAL_ASSERT for now, because of some unresolved macro conflicts
(possibly due to the SFML interface headers also including <cassert>):
despite redefining (#undef + #define) here, an assert(0) still did the
same old standard print + abort thing! :-o
  • Loading branch information
xparq committed Jul 13, 2024
1 parent 052b7ec commit 64efb9f
Showing 1 changed file with 35 additions and 5 deletions.
40 changes: 35 additions & 5 deletions include/SAL/util/diagnostics.hpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,46 @@
#ifndef _DFGNUDOSTDF8DM2HE87TYG87HY34870DFHYE98_
#define _DFGNUDOSTDF8DM2HE87TYG87HY34870DFHYE98_

//============================================================================
#ifdef DEBUG
//============================================================================

#include <cassert>
#include <iostream>
//
// Just have stderr handy...
//
//!! Grow a proper logging facility instead (or in addition), of course!
//!! (Don't forget to use OutputDebugString on Windows, like in my old DBG header!)
//
#include <iostream>
using std::cerr, std::endl, std::hex;

#else
//
// Pimped asserts from Chris Wellons (Skeeto) -- https://nullprogram.com/blog/2022/06/26/
// Instead of #include <cassert>, this breaks (for debugging) instead of printing and terminating.
//

// ...
//!!?? WTF, I sill got the stock assert despite this?!
//!!??# undef assert // SFML could've already included <cassert> before we get here...
//!!??

#endif
# if __GNUC__
# define SAL_ASSERT(c) if (!(c)) __builtin_trap()
# elif _MSC_VER
# define SAL_ASSERT(c) if (!(c)) __debugbreak()
# else
# define SAL_ASSERT(c) if (!(c)) *(volatile int *)0 = 0
# endif

//============================================================================
#else // DEBUG
//============================================================================


# define SAL_ASSERT(c)


//============================================================================
#endif // DEBUG
//============================================================================

#endif // _DFGNUDOSTDF8DM2HE87TYG87HY34870DFHYE98_

0 comments on commit 64efb9f

Please sign in to comment.