John Bode
3/21/2011 7:52:00 PM
On Saturday, March 19, 2011 1:29:43 PM UTC-5, Michael Press wrote:
> In article <ln1v23g...@nuthaus.mib.org>,
> Keith Thompson <ks...@mib.org> wrote:
>
> > Michael Press <rub...@pacbell.net> writes:
> > > int main(void)
> > > {
> > > ---3;
> > > return 0;
> > > }
> > >
> > > error: invalid lvalue in decrement
> > >
> > > ???
> > > Why does this have to be an error?
> > > The value could be -4 or -3 or -2.
> > > If somebody [shuffles feet] wants
> > > to use this construction, then who
> > > would stop him?
> >
> > Apart from the fact that "---3;" is a constraint violation, and
> > that every conforming compiler must issue a diagnostic for it, and
> > in practice I suspect that every existing compiler will reject it:
> >
> > Whatever you intended "---3" to mean, there is certainly a
> > clearer way to express that meaning. For the most nearly sensible
> > interpretation, just write either "-3 - 1" or "-4". Or, since
> > you're discarding the result, just delete that line of code.
>
> First, I am brain dead for writing ---3,
> and acting as if 3 can be decremented.
>
> Second, it can be parsed as (-(-(-(3)))),
> but is not.
>
Don't confuse tokenizing with parsing. The source code must be converted into tokens before it can be parsed, and per the "maximal munch" rule, the code will always be tokenized as "-- -3". "---" will always be tokenized as "-- -".
> Third
>
> int main(void)
> {
> int x = 3;
>
> ---x;
>
> return 0;
> }
>
> gets the same error.
> In function 'main':
> error: invalid lvalue in decrement
>
That's because the result of -x is not an lvalue, and the operand of -- must be an lvalue.
> A warning is well deserved.
> ---x can be parsed into
> something meaningful in C.
>
"---x" will be *tokenized* into "-- -x", which is *parsed* as "--(-x)", which is invalid as described above.