In a function call, what is the operator, and what are the operands?

吃可爱长大的小学妹 提交于 2019-12-06 17:50:47

问题


I am trying to understand some basics of C. KRC's The C Programming Language says

A function call is a postfix expression, called the function designator, followed by parentheses containing a possibly empty, comma-separated list of assignment expressions (Par.A7.17), which constitute the arguments to the function.

  1. In a function call, what is the operator, and what are the operands?

    Is () the operator?

    Is the function name an operand?

    Are the arguments inside () operands?

  2. Is a function designator a synonym of a function call?

Thanks.


回答1:


In a function call, () is an operator just like [] is an operator when accessing an array element.

6.5.2 Postfix operators

Syntax
1 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 , }

argument-expression-list:
assignment-expression
argument-expression-list , assignment-expression  

Operand for this operator is the function name (or a pointer to the function).

Are the arguments inside () operands?

No. As per the C standard the list of expressions specifies the arguments to the function.




回答2:


The text in the C standard is nearly identical, 6.5.2.2:

A postfix expression followed by parentheses () containing a possibly empty, comma-separated list of expressions is a function call. The postfix expression denotes the called function. The list of expressions specifies the arguments to the function.

The syntax is (6.5.2):

postfix-expression ( argument-expression-listopt )

This means that the function name is a "postfix-expression" and the ( ) is the actual operator. The C standard does not speak of operands for this operator, but I suppose you could call the function name an operand. The argument list is not an operand, but rather a special case.


The definition of a function designator is (6.3.2.1):

A function designator is an expression that has function type.

Meaning in the expression func();, func would be the function designator but the expression as whole would be a function call. So it is not exactly the same term.

Consider the example funcptr_t f = func; which involves the function designator func but no function call.



来源:https://stackoverflow.com/questions/45615818/in-a-function-call-what-is-the-operator-and-what-are-the-operands

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!