16

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.

Lundin
  • 195,001
  • 40
  • 254
  • 396
Tim
  • 1
  • 141
  • 372
  • 590
  • 2
    Function call is defined in the yellow box, and it is obviously *not* the function designator, which is the function name. – Eugene Sh. Aug 10 '17 at 14:04

2 Answers2

11

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.

haccks
  • 104,019
  • 25
  • 176
  • 264
  • 3
    formal grammar definition is definitely what the beginners need the most :) – 0___________ Aug 10 '17 at 14:34
  • 2
    *operand* is essentially a synonym of *argument*. -- *[An operand, then, is also referred to as "one of the inputs (quantities) for an operation".](https://en.wikipedia.org/wiki/Operand)* – Octopus Aug 10 '17 at 17:34
  • 1
    @PeterJ, perhaps, but the OP has a rep of 23K, hardly a beginner. – Octopus Aug 10 '17 at 17:36
5

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.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
Lundin
  • 195,001
  • 40
  • 254
  • 396
  • 3
    Btw, knowing these things is pretty much useless knowledge to anyone who isn't writing a compiler. – Lundin Aug 10 '17 at 14:16
  • 1
    *I suppose you could call the function name an operand.* This is not common practice: the word *operand* in the context of a function call more often designates each of the expressions in the argument list, a synonym for argument. The C Standard does not use *operand* for this, nor for macro arguments or parameters, but specifications for other programming languages do, such as Python. – chqrlie Aug 10 '17 at 14:43
  • @chqrlie Hence the "I suppose" :) I did emphasize that the standard does not mention any operands in this case. – Lundin Aug 10 '17 at 14:51
  • Note §6.5.2.2 ¶1 says: _The expression that denotes the called function (92) shall have type pointer to function returning void or returning a complete object type other than an array type._ Footnote 92 says: _Most often, this is the result of converting an identifier that is a function designator._ And §6.3.2.1 continues: _Except when it is the operand of the sizeof operator,(65) or the unary & operator, a function designator with type ‘‘function returning type’’ is converted to an expression that has type ‘‘pointer to function returning type"._ – Jonathan Leffler Aug 10 '17 at 15:19
  • @JonathanLeffler: there is no question a function designator can be used as the operand of some operators, that does not make it the operand of the function call operator, which is not designated as such either. – chqrlie Aug 10 '17 at 15:44