MT Core (C++)
Core library for replacing C++ standard in project usage
Loading...
Searching...
No Matches
Macros

Macros. More...

Macros

#define EXIT_MAX   255
 Maximum exit code value.
 
#define EXIT_ABORT   EXIT_MAX
 Exit code value to indicate program was aborted due to invalid state (e.g.
 
#define mt_print_cur_stacktrace(...)
 Prints the current stack trace with an optional message.
 
#define mt_print_stacktrace(TRACE, ...)
 Prints a specific stack trace with an optional message.
 
#define ensure(check, ...)
 Ensures that a check holds true, aborts the program if not true Will print error if the condition is false.
 
#define unreachable(...)
 Marks code as unreachable.
 
#define mtdefer   auto DEFER(__LINE__) = mtcore::defer_impl::DeferrerBuilder{} + [&]()
 Defer statement that will mtdefer execution until the scope is left, at which point the code will run Execution will happen regardless of whether there was an error.
 

Detailed Description

Macros.

Macro Definition Documentation

◆ ensure

#define ensure ( check,
... )
Value:
if (!(check)) { \
mt_print_cur_stacktrace("\nCONDITION FAILED!\n\t" \
"CONDITION: %s\n\t" \
"MESSAGE: %s\n\t" \
"WHERE: %s:%d\n\t" \
"ERRNO: " \
"%d\n\tERRNO DESC: %s\n", \
#check, #__VA_ARGS__, __FILE__, __LINE__, errno, strerror(errno)); \
abort(); \
}

Ensures that a check holds true, aborts the program if not true Will print error if the condition is false.

Parameters
checkThe Check to ensure is true

Definition at line 216 of file core/mtcore/core.hpp.

216#define ensure(check, ...) \
217 if (!(check)) { \
218 mt_print_cur_stacktrace("\nCONDITION FAILED!\n\t" \
219 "CONDITION: %s\n\t" \
220 "MESSAGE: %s\n\t" \
221 "WHERE: %s:%d\n\t" \
222 "ERRNO: " \
223 "%d\n\tERRNO DESC: %s\n", \
224 #check, #__VA_ARGS__, __FILE__, __LINE__, errno, strerror(errno)); \
225 abort(); \
226 }

◆ EXIT_ABORT

#define EXIT_ABORT   EXIT_MAX

Exit code value to indicate program was aborted due to invalid state (e.g.

failed ensure)

Definition at line 134 of file core/mtcore/core.hpp.

◆ EXIT_MAX

#define EXIT_MAX   255

Maximum exit code value.

Definition at line 126 of file core/mtcore/core.hpp.

◆ mt_print_cur_stacktrace

#define mt_print_cur_stacktrace ( ...)
Value:
(void) fprintf(stderr, __VA_ARGS__); \
(void) fflush(stderr); \
cpptrace::stacktrace::current(1).print(std::cerr);

Prints the current stack trace with an optional message.

Definition at line 146 of file core/mtcore/core.hpp.

146#define mt_print_cur_stacktrace(...) \
147 (void) fprintf(stderr, __VA_ARGS__); \
148 (void) fflush(stderr); \
149 cpptrace::stacktrace::current(1).print(std::cerr);

◆ mt_print_stacktrace

#define mt_print_stacktrace ( TRACE,
... )
Value:
(void) fprintf(stderr, __VA_ARGS__); \
(void) fflush(stderr); \
(TRACE).print(std::cerr);

Prints a specific stack trace with an optional message.

Definition at line 163 of file core/mtcore/core.hpp.

163#define mt_print_stacktrace(TRACE, ...) \
164 (void) fprintf(stderr, __VA_ARGS__); \
165 (void) fflush(stderr); \
166 (TRACE).print(std::cerr);

◆ mtdefer

#define mtdefer   auto DEFER(__LINE__) = mtcore::defer_impl::DeferrerBuilder{} + [&]()

Defer statement that will mtdefer execution until the scope is left, at which point the code will run Execution will happen regardless of whether there was an error.

Example Usage:

auto fd = fopen(...);
if (!fd) return -1;
mtdefer { fclose(fd); };
#define mtdefer
Defer statement that will mtdefer execution until the scope is left, at which point the code will run...

Definition at line 357 of file core/mtcore/core.hpp.

◆ unreachable

#define unreachable ( ...)
Value:
mt_print_cur_stacktrace("\nUNREACHABLE!\n\t" \
"MESSAGE: %s\n\t" \
"WHERE: %s:%d\n\t" \
"ERRNO: " \
"%d\n\tERRNO DESC: %s\n", \
#__VA_ARGS__, __FILE__, __LINE__, errno, strerror(errno)); \
__builtin_unreachable(); \
abort();
#define mt_print_cur_stacktrace(...)
Prints the current stack trace with an optional message.

Marks code as unreachable.

If hit, will crash the program

Definition at line 246 of file core/mtcore/core.hpp.

246#define unreachable(...) \
247 mt_print_cur_stacktrace("\nUNREACHABLE!\n\t" \
248 "MESSAGE: %s\n\t" \
249 "WHERE: %s:%d\n\t" \
250 "ERRNO: " \
251 "%d\n\tERRNO DESC: %s\n", \
252 #__VA_ARGS__, __FILE__, __LINE__, errno, strerror(errno)); \
253 __builtin_unreachable(); \
254 abort();