11.12.3.6.16. Define ENSURE_OR_RETURN_ON_ERROR

11.12.3.6.16.1. Define Documentation

ENSURE_OR_RETURN_ON_ERROR(CONDITION, RETURN_VALUE)

If condition fails, return

int SomeAPI()
{
    ...

    status = Operation1();
    ENSURE_OR_RETURN_ON_ERROR(0 == status, ERR_FAIL);

    status = Operation2();
    ENSURE_OR_RETURN_ON_ERROR(0 == status, ERR_NOT_ENOUGH_SPACE);

    ...

    return 0;
}

Warning

This macro introduces system of mutliple returns from a function which is not easy to debug/trace through and hence not recommended.