From a39a53cf167337edf8dc7be13925adb77cb6e7ad Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Wed, 21 Nov 2012 22:38:31 +0100 Subject: digital/ucoolib: add assert function No assert message, no file, no line number, no fat. --- digital/ucoolib/ucoolib/common.hh | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'digital/ucoolib/ucoolib/common.hh') diff --git a/digital/ucoolib/ucoolib/common.hh b/digital/ucoolib/ucoolib/common.hh index a27dfe3b..5be6227f 100644 --- a/digital/ucoolib/ucoolib/common.hh +++ b/digital/ucoolib/ucoolib/common.hh @@ -35,6 +35,41 @@ barrier () __asm__ __volatile__("": : : "memory"); } +/// Stop, abruptly. +void +halt () __attribute__ ((noreturn)); + +/// Stop, try to output error description corresponding to errno. +void +halt_perror () __attribute__ ((noreturn)); + +/// To be used to swear that the given condition is true. If this is not the +/// case... well... you swore! +extern inline void +assert (bool condition) +{ + if (!condition) + halt (); +} + +/// To be used to swear that this code can never be reached. +void +assert_unreachable () __attribute__ ((noreturn)); +extern inline void +assert_unreachable () +{ + halt (); +} + +/// To be used to swear that the given condition is true, but print errno +/// description anyway in case you lied. +extern inline void +assert_perror (bool condition) +{ + if (!condition) + halt_perror (); +} + } // namespace ucoo #endif // ucoolib_common_h -- cgit v1.2.3