表达式中的大括号 returns "statement with no effect"
Braced-group within expression returns "statement with no effect"
我想在表达式中使用括号组,它是 C 的 GNU 扩展。编译器将评估整个块并使用块中包含的最后一条语句的值。下面的代码将打印 5,但是当我用 gcc
编译它时它 return 是一个警告
warning: statement with no effect [-Wunused-value]
typeof(5) x = ({1; 2;}) + 3; // The warning points to "1"
printf("%d\n", x);
如果这个表达式是由 GNU 生成的,为什么 GCC 编译器 return 会发出警告?
Why would the GCC compiler return a warning if this expression was made by GNU?
gcc
不抱怨 GNU 扩展本身。
相反,语句 1;
是无用的,因为 statement expression 的结果在没有它的情况下是相同的,因为 ({1; 2;})
的最终结果是 2。
即相当于:
typeof(5) x = ({2;}) + 3;
so gcc
警告语句 1;
无效。
我想在表达式中使用括号组,它是 C 的 GNU 扩展。编译器将评估整个块并使用块中包含的最后一条语句的值。下面的代码将打印 5,但是当我用 gcc
编译它时它 return 是一个警告
warning: statement with no effect [-Wunused-value]
typeof(5) x = ({1; 2;}) + 3; // The warning points to "1"
printf("%d\n", x);
如果这个表达式是由 GNU 生成的,为什么 GCC 编译器 return 会发出警告?
Why would the GCC compiler return a warning if this expression was made by GNU?
gcc
不抱怨 GNU 扩展本身。
相反,语句 1;
是无用的,因为 statement expression 的结果在没有它的情况下是相同的,因为 ({1; 2;})
的最终结果是 2。
即相当于:
typeof(5) x = ({2;}) + 3;
so gcc
警告语句 1;
无效。