11.12.3.6.12. Define ENSURE_OR_EXIT_WITH_STATUS_ON_ERROR

11.12.3.6.12.1. Define Documentation

ENSURE_OR_EXIT_WITH_STATUS_ON_ERROR(CONDITION, STATUS, RETURN_VALUE)

If condition fails, goto quit with return value status updated.

int SomeAPI()
{
    int status = 0;
    ...

    value = Operation1();
    ENSURE_OR_QUIT_WITH_STATUS_ON_ERROR(0 == value, status, ERR_FAIL);

    value = Operation2();
    ENSURE_OR_QUIT_WITH_STATUS_ON_ERROR(0 == value, status, ERR_NOT_ENOUGH_SPACE);

    ...
quit:
    return status;
}

Warning

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