C++ assert(0)

C++ assert(0)

assert(0)

In TensorRT/samples/common/logging.hthe LogStreamConsumer:: severityPrefixuse of assert(0):

class LogStreamConsumer : protected LogStreamConsumerBase, public std::ostream
{
//...
private:
    static std::string severityPrefix(Severity severity)
    {
        switch (severity)
        {
        //F for FATAL?
        case Severity::kINTERNAL_ERROR: return "[F] ";
        case Severity::kERROR: return "[E] ";
        case Severity::kWARNING: return "[W] ";
        case Severity::kINFO: return "[I] ";
        case Severity::kVERBOSE: return "[V] ";
        default: assert(0); return "";
        }
    }
    //...
};

Reference ? The What does the Assert (0) Mean , assert(0)is used to mark the "only reachable if there is a bug in my code" part with, that is, under normal circumstances, the program should not come to defaultthis branch; if to this branch, it shows the presence of a bug in the code.

Reference Links

What does assert(0) mean?

Published 90 original articles · won praise 9 · views 50000 +

Guess you like

Origin blog.csdn.net/keineahnung2345/article/details/104076488