3 ms·
If a function returns 0 when it succeeds and some nonzero value as an error code when it fails, then you can write if(myfunc(...)) { ...
by aisofteng 9y ago
If a function returns 0 when it succeeds and some nonzero value as an error code when it fails, then you can write
if(myfunc(...)) { ...
- a_t48 9y agoThis works fine until you have some other function that returns 0 on failure.
- aisofteng 9y agoThis has never been a problem for me and I've never heard of it being a problem for anyone else.
- a_t48 9y agoSuccess being false is definitely an odd pattern to me. I know I’m not the only one tripped up by it (‘canWrite()’ should return true on success...except if you want to return an error code by value). This is sort of fixed with C++ ‘enum class’, but obviously this isn’t always possible to use.