【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.

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.

#define ERR_LINE (-__LINE__)

int foo()
{
    if (...) {
        return ERR_LINE;
    }      
}

 

posted @ 2018-07-25 15:55  AlbumCover  阅读(136)  评论(0)    收藏  举报