Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #67628

Re: Parentheses as operators

From James Kuyper <jameskuyper@verizon.net>
Newsgroups comp.lang.c
Subject Re: Parentheses as operators
Date 2015-08-17 16:26 -0400
Organization Self
Message-ID <55D24379.9090205@verizon.net> (permalink)
References <operator-20150817203200@ram.dialup.fu-berlin.de>

Show all headers | View raw


On 08/17/2015 02:50 PM, Stefan Ram wrote:
>   To me, an operator is a sequence of fixed tokens and gaps
>   that yields an expression, when expressions are inserted
>   into the gaps. For example:
> 
>     .-----.     .-.     .-----.     .-.     .-----.
> --->| gap |--->( ? )--->| gap |--->( : )--->| gap |--->
>     '-----'     '-'     '-----'     '-'     '-----'
> 
>   yields the expression »0?1:2«, when the expressions
>   »0«, »1«, and »2« are inserted into the gaps.
> 
>   Therefore, to me, this is also an operator:
> 
>      .-.     .-----.     .-.
> --->( ( )--->| gap |--->( ) )--->
>      '-'     '-----'     '-'
> 
>   , it yields the expression »(0)«, when the expression »0«
>   is inserted into the gap.
> 
>   But the parentheses usually do not count as an operator:
> 
> 6.5.3 Unary operators
> Syntax
> 1 unary-expression:
> postfix-expression
> ++ unary-expression
> -- unary-expression
> unary-operator cast-expression
> sizeof unary-expression
> sizeof ( type-name )
> _Alignof ( type-name )
> unary-operator: one of
> & * + - ~ !
> 
>   . The parentheses are given in
> 
> 6.5.1 Primary expressions
> Syntax
> 1 primary-expression:
> identifier
> constant
> string-literal
> ( expression )
> generic-selection
> 
>   . Of course, the parentheses are there in the syntax.
>   I do not want to deny this. But they never seemed to be called
>   an »operator«, not in the standard nor by people as far as
>   I am aware of. So I wonder why they are not called »operator«.

On 1999-12-08, I referred to them as operators, but Paul Jarc objected.

>   Some people might say that the parentheses are not an
>   operator because they are not compiled into an operation,
>   but isn't this also true of »+« as in »+0«, which also is
>   not compiled into an operation? Yet, the »+« /is/ called
>   an »operator«.
> 
>   Would it be wrong to call the parentheses an »operator«?

Paul Jarc thought so. Uncharacteristically, I didn't argue with him - I
wonder why?. It could be because this is one of the less clear parts of
the standard.

6.4.6p1 defines what constitutes a punctuator; parentheses are included.

"A punctuator is a symbol that has independent syntactic and semantic
significance. Depending on context, it may specify an operation to be
performed (which in turn may yield a value or a function designator,
produce a side effect, or some combination thereof) in which case it is
known as an _operator_ (other forms of operator also exist in some
contexts)." (6.4.6p2). The word "operator" is italicized, an ISO
convention indicating that this clause is the official definition of
that term.

One argument against calling parentheses operators could be that they
don't specify any operation to be performed - a parenthesized expression
is almost entirely equivalent to the expression itself, except that it
qualifies as primary-expression, which affects how it is parsed in
combination with other operators and operands.
Also, every sub-section of 6.5 has a name that includes the word
"operator", except for 6.5.1, which implies that none of the things
described there are operators.

Against this I would cite 6.5p1: "An _expression_ is a sequence of
operators and operands ...". Again, "expression" is italicized, so this
is a definition of that term. A parenthesized expression is itself a
primary-expression, and therefore an expression. If the parentheses
aren't operators in a parenthesized expression, that only leaves the
option, according to 6.5p1, of them being operands, which makes even
less sense.

The standard frequently refers to particular things as operators (and it
never does so for parentheses), but it seldom says anything about
operators in general, only specific operators. I was going to write
"never" rather than "seldom", but I found one exception:
6.2.6.1p8: "Where an operator is applied to a value that has more than
one object representation, which object representation is used shall not
affect the value of the result."

If parentheses are not operators, then this clause doesn't apply to
parenthesized expressions.

Back to comp.lang.c | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

Re: Parentheses as operators James Kuyper <jameskuyper@verizon.net> - 2015-08-17 16:26 -0400
  Re: Parentheses as operators Keith Thompson <kst-u@mib.org> - 2015-08-17 14:45 -0700

csiph-web