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


Groups > comp.lang.c > #401562

Re: Meaning of "expression"

From Tim Rentsch <tr.17687@z991.linuxsc.com>
Newsgroups comp.lang.c
Subject Re: Meaning of "expression"
Date 2026-08-28 17:23 -0700
Organization A noiseless patient Spider
Message-ID <86y0dpwz9j.fsf@linuxsc.com> (permalink)
References (16 earlier) <86bjdpayv0.fsf@linuxsc.com> <10vv49k$1aoa2$4@kst.eternal-september.org> <1107aq2$3grso$2@kst.eternal-september.org> <86jypr6d96.fsf@linuxsc.com> <115pmgh$3c96f$1@kst.eternal-september.org>

Show all headers | View raw


Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:

> Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
>
>> Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
>>
>>> Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
>>> [...]
>>>
>>>> The actual text of the standard implies that 42 is not an
>>>> expression.  I rely on the obvious intent to conclude that it is.
>>>
>>> I made the above statement to demonstrate that just following the
>>> exact wording of the standard, without thinking about the (sometimes
>>> unclear) intent behind it, can lead to absurd results.
>>>
>>> I've discussed this particular glitch before, but it's been a while.
>>>
>>> N3220 6.5.1 says:
>>>
>>>     An *expression* is a sequence of operators and operands that
>>>     specifies computation of a value, or that designates an object
>>>     or a function, or that generates side effects, or that performs
>>>     a combination thereof.
>>>
>>> I believe the wording is unchanged from C90 up to the latest C202y
>>> draft.  Since the word "expression" is in italics, this is the
>>> standard's definition of the word.
>>>
>>> This is a flawed definition.  The terms "operator" and "operand"
>>> are defined in 6.4.6:
>>>
>>>     *punctuator: one of
>>>         [ ] ( )
>>>     [snip]
>>>
>>>     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).  An *operand* is an
>>>     entity on which an operator acts.
>>>
>>> Consider this expression statement:
>>>
>>>     42;
>>>
>>> Is `42` an expression?  Clearly it's intended to be, but there is no
>>> operator, and therefore there is no operand, so it doesn't meet the
>>> standard's definition of the word "expression".
>>
>> I think this conclusion can be explained as a misreading of the text
>> in the C standard.  In reading the text "An *expression* is a
>> sequence of operators and operands", I think you are interpreting it
>> as meaning "at least one of each of operators and operands".  But
>> this text could also be read as "at least one of either of operators
>> and operands", or in other words a sequence of elements of the set
>> containing both operands and operators, in which case 42 would
>> qualify as an expression.
>
> No.  The term "operand" is defined in N3220 6.4.6p2:
>
>     An *operand* is an entity on which an operator acts.
>
> As I already explained, in the expression statement `42;`, 42 it
> is neither an operator nor an operand.  [...]

Thank you for the explanation.  Sorry for the confusion.

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


Thread

Re: Meaning of "expression" Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-08-15 00:42 -0700
  The meaning of 42 ; (was: Re: Meaning of "expression") Johann 'Myrkraverk' Oskarsson <johann@myrkraverk.invalid> - 2026-08-15 19:42 +0800
  Re: Meaning of "expression" Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2026-08-15 05:36 -0700
    Re: Meaning of "expression" Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-08-28 17:23 -0700

csiph-web