在理解printf(“%d \ n")的方式后,({int n; scanf(“%d",& n); n * n;}});在C中工作
此代码使用了称为语句表达式的"GNU C"功能,括号内的复合语句可用作表达式,其类型和值与复合语句中最后一条语句的结果匹配.这在语法上不是有效的C语言,而是GCC功能(也为其他一些编译器所采用)是由于被认为对编写不重复评估其参数的宏而被认为很重要而添加的.
This code is using a "GNU C" feature called statement-expressions, whereby a parentheses-enclosed compound statement can be used as an expression, whose type and value match the result of the last statement in the compound statement. This is not syntactically valid C, but a GCC feature (also adopted by some other compilers) that was added presumably because it was deemed important for writing macros which do not evaluate their arguments more than once.
如果您在必须阅读的代码中遇到它,您应该知道它的含义和作用,但是我会避免自己使用它.这是令人困惑,不必要和非标准的.静态内联函数几乎总是可以移植相同的东西.
You should be aware of what it is and what it does in case you encounter it in code you have to read, but I would avoid using it yourself. It's confusing, unnecessary, and non-standard. The same thing can almost always be achieved portably with static inline functions.