C中的完整表达是什么? [英] What is a full expression in C?

查看:91
本文介绍了C中的完整表达是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从斯蒂芬·普拉塔(Stephen Prata)的"C Primer Plus"一书中学习C语言,并得出了要点:

I study C language from "C Primer Plus" book by Stephen Prata and it came to the point :

完整的表达式不是较大的子表达式完整表达式的示例包括表达式语句和用作测试条件的表达式一会儿循环"

"A full expression is one that’s not a subexpression of a larger expression.Examples of full expressions include the expression in an expression statement and the expression serving as a test condition for a while loop"

我不明白完整表达式的确切定义是什么,以及为什么书认为测试条件是完整表达式.

I can't understand clearly what is the exact definition of full expressions and why the book considers test conditions are full expressions.

任何人都可以清楚地解释完整表达式"的含义吗,我如何指定一个表达式是否为完整表达式?

Could any one explain clearly what is meant by "Full Expression" and how can I specify that an expression is full expression or not ?

推荐答案

他直接从C标准中获取了这一点,例如C11 6.8:

He's taken this straight from the C standard, example C11 6.8:

完整表达式是一个表达式,它不属于另一个表达式或声明符.以下每个都是完整表达式:不属于化合物的初始化程序文字;表达式语句中的表达式;选择的控制表达语句( if switch ); while do 语句的控制表达式;每个 for 语句的(可选)表达式的形式;返回中的(可选)表达式陈述.在对完整表达式的评估与对表达式的评估之间存在一个序列点.评估要评估的下一个完整表达式.

A full expression is an expression that is not part of another expression or of a declarator. Each of the following is a full expression: an initializer that is not part of a compound literal; the expression in an expression statement; the controlling expression of a selection statement (if or switch); the controlling expression of a while or do statement; each of the (optional) expressions of a for statement; the (optional) expression in a return statement. There is a sequence point between the evaluation of a full expression and the evaluation of the next full expression to be evaluated.

一些例子是:

if(x)

for(x; y; z)

返回x;

其中x y和z是完整表达式.

完整表达式是语言语法术语,并不是C程序员真正需要了解的东西.它仅与语言律师"以及从事编译器或静态分析器的人员有关.C标准说的是语句完整表达式.

Full expression is a language grammar term and not really something a C programmer needs to know about. It is only relevant to "language lawyers" and those making compilers or static analysers. The C standard speaks of statements, blocks and full expressions.

程序员可能需要知道的是以上引用的文本的最后一句话,这意味着在完整的表达后,该表达的所有副作用都将被执行.因此,如果我编写诸如 if(i ++)printf(%d",i); 之类的代码,那么我知道 i ++ 已在printf行之前执行.

What the programmer might need to know is the last sentences of the above cited text, which means that after a full expression, all side effects of that expression are carried out. So if I write code such as if(i++) printf("%d", i); then I know that the i++ has been carried out before the printf line.

但是,在阅读编译器错误时,了解这些干燥的语法术语可能会非常有用.例如臭名昭​​著的声明遗失",用通俗的英语来说,很可能意味着您忘记了分号.

It may however be quite useful to know these dry grammar terms when reading compiler errors. Such as the infamous "statement missing", that most likely means, in plain English, that you've forgotten a semicolon.

这篇关于C中的完整表达是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆