Ignoring return values in C

前端 未结 10 1431
轻奢々
轻奢々 2020-12-08 13:39

Lately, I started using lint for static code analysis. One of the warning I get sometimes is regarding this issue. Let\'s say for instance that I\'ve got the following funct

10条回答
  •  攒了一身酷
    2020-12-08 14:05

    gnulib has this: http://git.savannah.gnu.org/cgit/gnulib.git/tree/lib/ignore-value.h

    /* Normally casting an expression to void discards its value, but GCC
       versions 3.4 and newer have __attribute__ ((__warn_unused_result__))
       which may cause unwanted diagnostics in that case.  Use __typeof__
       and __extension__ to work around the problem, if the workaround is
       known to be needed.  */
    #if 3 < __GNUC__ + (4 <= __GNUC_MINOR__)
    # define ignore_value(x) \
        (__extension__ ({ __typeof__ (x) __x = (x); (void) __x; }))
    #else
    # define ignore_value(x) ((void) (x))
    #endif
    

提交回复
热议问题