gpt4 book ai didi

c - C 中的完整表达式是什么?

转载 作者:太空狗 更新时间:2023-10-29 16:43:48 24 4
gpt4 key购买 nike

我从 Stephen Prata 的“C Primer Plus”一书中学习 C 语言,它来到了这一点:

"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"

完全表达式的确切定义是什么,以及为什么本书认为测试条件是完全表达式,我都不清楚。

任何人都可以清楚地解释“完整表达式”的含义以及我如何指定表达式是否为完整表达式?

最佳答案

他直接从 C 标准中提取了这个,例如 C11 6.8:

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.

一些例子是:

如果(x)

for(x; y; z)

返回 x;

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

完整表达式 是一个语言语法术语,并不是 C 程序员真正需要了解的东西。它只与“语言律师”和那些制作编译器或静态分析器的人有关。 C 标准涉及语句 block 完整表达式

程序员可能需要知道的是上面引用的文本的最后一句,意思是在一个完整的表达式之后,执行该表达式的所有副作用。因此,如果我编写诸如 if(i++) printf("%d", i); 之类的代码,那么我就知道 i++ 已经在 printf 行之前执行了。

然而,在阅读编译器错误时了解这些枯燥的语法术语可能非常有用。例如臭名昭​​著的“语句丢失”,用简单的英语来说,很可能意味着您忘记了分号。

关于c - C 中的完整表达式是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48880037/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com