Warning “Use of GNU statement expression extension”

后端 未结 4 1539
谎友^
谎友^ 2021-01-04 11:09

I have this Objective-C istruction:

NSRange range = NSMakeRange(i, MIN(a, b));

where a and bare NSUInteger<

相关标签:
4条回答
  • 2021-01-04 11:31

    It’s a late answer, I know, but you can avoid this message by adding -Wno-gnu to your compiler flags.

    (In Xcode 5 I believe you can change this by going to your project’s Build Settings and adding -Wno-gnu to the “Other C Flags”, which are in the “Apple LLVM 5.0 – Custom Compiler Flags” section.)

    0 讨论(0)
  • 2021-01-04 11:40

    "Statement expressions" is an extension of the GNU C compiler and allows you to execute a group of statements, returning the value of the last statement:

    x = ({
        statement1;
        statement2;
        statement3;
    });
    

    In the above example, x will have the value returned by statement3.

    It is a convenient feature that enables you to have multi-statement macros that can be nested easily into other expressions. It is not, however, defined by any C standard.

    0 讨论(0)
  • 2021-01-04 11:42

    Don't use -Wno-gnu, that shuts down too many warnings. Instead, use:

    -Wno-gnu-statement-expression
    
    0 讨论(0)
  • 2021-01-04 11:56

    Statement expressions have been declared.

    You can selectively ignore the warning by using pragma codes without changing project settings.

    #pragma GCC diagnostic push
    #pragma GCC diagnostic ignored "-Wgnu"
    
    NSRange range = NSMakeRange(i, MIN(a, b));
    
    #pragma GCC diagnostic pop
    
    0 讨论(0)
提交回复
热议问题