There's no need. Any debugger can tell exactly the line where the segfault error comes from if it occurs. |
Assuming the program is run in a debugger and was compiled in a debugger-friendly manner (debug symbols, limited optimization). Even given the latter, I can think of at least one case in which you're likely to run a such a program outside of a debugger.
I have edited program_assert() macro. |
program_assert knocks one issue off the list, but not the rest.
Does it work exactly like "breakpoint" featured in any C++ debugger? |
Your debugger or GUI interface thereof should function roughly the same as when a segfault happens. My copy of gdb halts when that happens and I'm told Visual C++'s debugger does as well.
std::raise().
Dereferencing nullptr may not be "fatal-ish" enough due to that the memory address is never used. 123 is a more valid memory address and may contain protected data, so I think this will do. |
If you really want the assertion to be fatal,
then why not avoid relying on undefined behavior? You yourself said that 0x7B *may* contain protected data, that means you don't trust that it always will kill your program. In fairness, dereferencing nullptr is also undefined, I was just curious why you chose one "solution" over the more obvious.
Remember that (some_expression && "Error message!") always evaluates to 1. |
Nope. Wrong. No way around this one, this is just dead wrong, and I do have code that demonstrates as much. Of course, you came to the same conclusion and deleted that message just before I replied, because I like to take my time with my posts, and put as much as I can into one post rather than triple or quadruple posting.
EDIT: Probably should clarify that this was in the context of the assert macro.
-Albatross