【trick】use negative line number as return value on error

For frequently modified functions without specified enum value returned on error, you may just return -1 or other magic number.spa

I prefer to make use of the line number as return value, which naturally indicates which line goes wrong across the lifetime of the everchanging code.code

#define ERR_LINE (-__LINE__)

int foo()
{
    if (...) {
        return ERR_LINE;
    }      
}
相關文章
相關標籤/搜索