CPlus
CPlus

Reputation: 4620

What is the purpose of assert(false) in an if?

I saw this in an example Apple project called Rendering Terrain Dynamically with Argument Buffers

if (buffers.size() > 1)
{
    assert (false);
    return;
}

How would this behave any differently than the simpler assert(buffers.size() <= 1)?

Upvotes: 2

Views: 217

Answers (1)

sbooth
sbooth

Reputation: 16966

In C assert is a macro that does nothing if NDEBUG is defined. In this case I'd guess assert(false) is inside the conditional to ensure that even if abort() is not called (because assert() was a no-op due to NDEBUG or redefinition) the function returns.

Upvotes: 1

Related Questions