Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 934
Tim Avatar asked Aug 10 '17 13:08

Tim


People also ask

What are operator and operands?

An operand can be a constant, a variable or a function result. Operators are arithmetic, logical, and relational. As with C, some operators vary in functionality according to the data type of the operands specified in the expression.

What is the function call operator?

A function call is a kind of postfix-expression , formed by an expression that evaluates to a function or callable object followed by the function-call operator, () . An object can declare an operator () function, which provides function call semantics for the object.

What is the difference between operator and operand with example?

The operators indicate what action or operation to perform. The operands indicate what items to apply the action to. An operand can be any of the following kinds of data items: Constant.

What is function call in C?

A function call is an important part of the C programming language. It is called inside a program whenever it is required to call a function. It is only called by its name in the main() function of a program. We can pass the parameters to a function calling in the main() function.


2 Answers

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.

like image 117
haccks Avatar answered Oct 25 '22 09:10

haccks


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.

like image 32
Lundin Avatar answered Oct 25 '22 11:10

Lundin