I was going through the topic of associativity of C operators.
There I came across this fact that the function call operator ()
has a left to right associativity. But associativity only comes to play when multiple operators of the same precedence occur in an expression. But I couldn't find any example involving function call operator where associativity plays a crucial role.
For example in the statement a = f(x) + g(x);
, the result depends on the evaluation order and not on the associativity of the two function calls.
Similarly the call f(g(x))
will evaluate function g()
first and then the function f()
. Here we have a nested function call and again associativity doesn't play any role.
The other C operators in this priority group are array subscript []
, postfix ++
and postfix --
. But I couldn't find any examples involving a combination of these operators with ()
where associativity plays a part in expression evaluation.
So my question is does the associativity of function call being defined as left to right affect any expression in C? Can anyone provide an example where the associativity of function call operator ()
does matter in expression evaluation?
f
is an expression itself (like one function pointer selected from an array)? – Fukuokaf()()()()
and it's valid C. See Grzegorz's answer for a possible example. – Fragmentaryf(a)(b)
was a call tof
passingb
then calling the result witha
(that is to say(f(b))(a)
) - would you? – Mcvey