I was looking at this page: https://en.cppreference.com/w/c/language/operator_precedence
What caught my attention was that the only description of the parenthesis operator was function call. Does this mean that the expression x = a * (b+c)-(d*e)
has two function calls?
I searched in C grammar and C standard but I was unable to find anything that either supports or contradicts this.
Parenthesis can be used as a function call operator, but that's not the only thing they're used for. They are also used for expression grouping as in your example.
What you're looking for is in section 6.5.1 of the C standard which discusses Primary Expressions:
Syntax
1
primary-expression: identifier constant string-literal ( expression ) generic-selection
...
5 A parenthesized expression is a primary expression. Its type and value are identical to those of the unparenthesized expression. It is an lvalue, a function designator, or a void expression if the unparenthesized expression is, respectively, an lvalue, a function designator, or a void expression.
As stated above, parenthesis can be used to group expressions.
The use as a function call operator is detailed in section 6.5.2 on Postfix Expressions:
postfix-expression: ... postfix-expression(argument-expression-list opt) ...
So in your expression:
x = a * (b+c)-(d*e)
The use of parenthesis here matches a Primary Expression but not a Postfix Expression.
Also, besides expression grouping, parenthesis are used in other parts of the language grammar. Section 6.8.4 regarding Selection Statements uses parenthesis in the grammar of if
and switch
statements:
- if (expression) statement
- if (expression) statement else statement
- switch (expression) statement
And section 6.8.5 regarding Iteration Statements also use parenthesis in the grammar of while
and for
statements.
- while (expression) statement
- do statement while (expression);
- for (expressionopt; expressionopt; expressionopt) statement
- for (declaration expressionopt; expressionopt ) statement
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With