声明式/函数调用能不能算一个"表达式"? 为何?
本帖最后由 asker160 于 2016-07-04 16:56 编辑语言标准的第五章开明宗义的说:
[ Note: Clause 5 defines the syntax, order of evaluation, and meaning of expressions.58 An expression is a
sequence of operators and operands that specifies a computation. An expression can result in a value and
can cause side effects. — end note ]
我的理解是,一个expression定义了一个"computation",也就是可以计算的东西。
那么初始化语句
int i=1;
A obj;
上面两句能算是表达式吗? 定义一个变量1,给它一个初始值,这个编译出来是有"代码"的,要运行时"执行", 算不算一个表达式?
A obj声明一个实例,构造函数做了某些事情,这个是computation吗,算不算一个表达式?
Plus:
函数调用
f(1,2,3)
能算是一个expression吗? 看起来函数调用是能产生一个result,并且可以把函数调用作为参数进一步传给其他的函数来使用。
谢谢 本帖最后由 nswcfd 于 2016-07-13 16:20 编辑
函数调用应该是
(6.5.2) postfix-expression:
primary-expression
postfix-expression [ expression ]
postfix-expression ( argument-expression-listopt )
postfix-expression . identifier
postfix-expression -> identifier
postfix-expression ++
postfix-expression --
( type-name ) { initializer-list }
( type-name ) { initializer-list , }
声明(本身)感觉不像
(6.7) declaration:
declaration-specifiers init-declarator-listopt ;
static_assert-declaration
(6.7) init-declarator-list:
init-declarator
init-declarator-list , init-declarator
(6.7) init-declarator:
declarator
declarator = initializer
声明和语句是一个层次上的概念
表达式是表达式语句(语句的一种)的组成部分
当然声明中也有expression
不过貌似不能推出 declaration => ... => expression
(6.8.2) block-item:
declaration
statement
(6.8) statement:
labeled-statement
compound-statement
expression-statement
selection-statement
iteration-statement
jump-statement
(6.8.3) expression-statement:
expressionopt ;
页:
[1]