Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #401201 > unrolled thread
| Started by | Tim Rentsch <tr.17687@z991.linuxsc.com> |
|---|---|
| First post | 2026-08-15 00:42 -0700 |
| Last post | 2026-08-15 05:36 -0700 |
| Articles | 3 — 3 participants |
Back to article view | Back to comp.lang.c
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
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
| From | Tim Rentsch <tr.17687@z991.linuxsc.com> |
|---|---|
| Date | 2026-08-15 00:42 -0700 |
| Subject | Re: Meaning of "expression" |
| Message-ID | <86jypr6d96.fsf@linuxsc.com> |
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. An argument might be made about whether the text in the C standard _should_ mean that, but certainly it _could_ mean that.
[toc] | [next] | [standalone]
| From | Johann 'Myrkraverk' Oskarsson <johann@myrkraverk.invalid> |
|---|---|
| Date | 2026-08-15 19:42 +0800 |
| Subject | The meaning of 42 ; (was: Re: Meaning of "expression") |
| Message-ID | <TgYfS.340664$KyJ1.128902@fx13.ams4> |
| In reply to | #401201 |
On 15/08/2026 3:42 PM, Tim Rentsch wrote:
> 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.
>
> An argument might be made about whether the text in the C standard
> _should_ mean that, but certainly it _could_ mean that.
My compiler accepts
int main( int argc, char *argv[] ) {
42 ;
return 0 ;
}
and builds an executable out of it. Does yours?
--
Johann | email: invalid -> com | http://www.myrkraverk.com/blog/
I'm not from the Internet, I just work there. | via Easynews.com
https://bsky.app/profile/myrkraverk.bsky.social | for ( ;; ) _:;
[toc] | [prev] | [next] | [standalone]
| From | Keith Thompson <Keith.S.Thompson+u@gmail.com> |
|---|---|
| Date | 2026-08-15 05:36 -0700 |
| Message-ID | <115pmgh$3c96f$1@kst.eternal-september.org> |
| In reply to | #401201 |
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. It can't be an operand unless
there's an operator to act on it. So your reading of the text as
"at least one of either of operators and operands" doesn't help.
> An argument might be made about whether the text in the C standard
> _should_ mean that, but certainly it _could_ mean that.
It might be reasonable to define "operand" in a way that includes
a constant that is a full expression, but the standard clearly
doesn't say that.
To restate the obvious, my argument is not that `42` is not an
expression. It's that the standard's definition of "expression"
is flawed. The only sensible workaround is to pretend that `42`
is an expression -- basically to ignore the italicized definition of
"expression" and instead rely on the grammar production.
--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
void Void(void) { Void(); } /* The recursive call of the void */
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.c
csiph-web