Best practice for compute the function return value
Often I built functions, in C, that checks some parameters and return an error code. Which is the best approach to stop the values checking when I found an error? First example: ErrorCode_e myCheckFunction( some params ) { ErrorCode_e error = CHECK_FAILED; if( foo == bar ) { if( foo_1 == bar_1 ) { if( foo_2 == bar_2 ) { error = CHECK_SUCCESS; } } } return error; } Second Example: ErrorCode_e myCheckFunction( some params ) { if( foo != bar ) { return CHECK_FAILED; } if( foo_1 != bar_1 ) { return CHECK_FAILED; } if( foo_2 != bar_2 ) { return CHECK_SUCCESS; } } I prefer the first approach because