Indeed not. How could it be? Parentheses are used for all sorts of
quite different purposes in C: function calls, parameter lists, casts,
compound literals, declarators... even in some statements. All these
can be thought of "other syntax" with nothing to do with grouping in an
expression.
Yes, I just meant the () "operator".
My point was simply that there is another way to look at ()s and that it
is (a) adequate to explain how C's "grouping parentheses" and (b) it is
interesting in its own right in that it permits one to imagine new
expression forms that are normally discounted.
Hmm. I think it's not quite adequate to explain the grouping parentheses,
because there are cases in which it has effects beyond merely changing
grouping, but I can see it as a viable approximation.
Which brings me back to: The single-sentence description by Schildt is,
IMHO, "incorrect" -- it is not an accurate description. As a part of a
longer explanation, offered as a description of the net effect, I can see
how it would be useful.
I would never advocate using the notion I've been defending as a way to
explain C's "grouping parentheses" in C book. I was simply defending it
against an apparent wholesale rejection of the notion.
Ahh, I see.
When you have said "this is wrong" or "this is confusing" I thought you
were talking about something I'd said. Clearly, the above is confusing
and obviously wrong in many respects, but there is a germ of truth in
the statement about ()s and precedence.
Ahhh!
Okay, yeah. I was just arguing that Schildt's explanation is "wrong" -- as
in, if you read that explanation, you do not come away from it with an
accurate understanding of how grouping () work in expressions.
So, to summarize... False:
Parentheses are an operator which increase the precedence of
the operations within them.
True:
Parentheses can be used to group an expression, preventing the
normal precedence and associativity rules from changing the
interpretation of that expression when it is used in conjunction
with other operators. For instance, normally in C, the expression
"1 + 2 * 3" evaluates to 7, because the multiplication expression
is understood to be an operand to the addition operator; one way
to describe this is that multiplication has "higher precedence" than
addition. By contrast, "(1 + 2) * 3" evaluates to 9 because the
parentheses ensure that 3 is multiplied by the result of adding 1
and 2. In effect, parentheses raise the precedence of the operators
within them, so that the operands within the parentheses always
bind to those operators, rather than to operators outside the
parentheses.
(... true, I think, but badly phrased. Maybe I should try again
after breakfast.)
I had forgotten that this all started because of a statement in C:TCR.
That might explain the strength of your opposition to what I thought of
as an uncontentious observation: that ()s can be seen as syntax whose
role is to alter the precedence relationship between operators rather
than as syntax to group sub-expressions. I saw this exchange as
off-topic because I was not talking about any application of the idea to
understanding or parsing C expressions (specifically) whereas I think
you may have been thinking of it as an extended commentary on Schildt's
remark.
Yes, that would do it. I was thinking of it as a discussion, not of the
general habit of using () to group things in expressions, but specifically
of the expression-grouping () in C.
Thanks for sticking with this, I was pretty concerned because usually if
I disagree with you, it implies that I'm missing something significant.
It turns out, I think, to have been context.
-s