Search code examples
cobjective-cassertassertion

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)?


Solution

  • 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.