Prev: how to convert integer to string
Next: reinterpret_cast
From: James Dennett on 10 Jan 2006 13:20 Ralph D. Ungermann wrote: > James Dennett wrote: > >> Interesting: I much prefer that to the modern practice of >> writing assert(false) in theoretically unreachable places. > > > Ever tried something like > > assert( !"Oops: Can't remove object -- list is empty." ); Yes, and the variant assert( condition && !"Well, that didn't go so well" ); > The assert macro prints the offended expression. So you'll get some > sorce code documentation and a useful message for free! It is common practice for assert to display the failed expression, though it's not required AFAIK by C90 or C++98, only by C99 so far. One factor to consider, though, is that the idiom you note above is not common practice, while assert(false) is something that most professional programmers will recognize as meaning "unreachable". -- James
From: Old Wolf on 10 Jan 2006 18:43
Ralph D. Ungermann wrote: > James Dennett wrote: >> Interesting: I much prefer that to the modern practice of >> writing assert(false) in theoretically unreachable places. > > Ever tried something like > > assert( !"Oops: Can't remove object -- list is empty." ); > > The assert macro prints the offended expression Prints where? In an embedded situation this message is likely to just get lost; there is no convenient output stream for dumping debugging to. Hence the reason for the OP calling a panic function, which will presumably log the function call's parameters into a panic log which can then be accessed by a debugging tool. |