This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
RE: GCC's statement expression extension
- To: "'Linus Torvalds'" <torvalds at transmeta dot com>, Marc Espie <espie at quatramaran dot ens dot fr>
- Subject: RE: GCC's statement expression extension
- From: Anjul Srivastava <anjul dot srivastava at sanchez dot com>
- Date: Fri, 28 Jul 2000 15:01:48 -0400
- Cc: gcc at gcc dot gnu dot org
It does not have undefined behavior, and will always evaluate to: three plus
twice the old value of i.
But that's besides the point. Even if you consider: ++i + i++ the behavior
is undefined,
but it cannot format your hard disk and still remain conforming. It cannot
ever return 42, regardless of the value of i. (It can only return an odd
integer but this again is besides the point).
The C/C++ standards leave only the order of evaluation undefined. They say
that of the possible choices of order of evaluation, which one is selected
is undefined. But the fact that one of them is selected is mandated by the
standard. That's why 42 is out, and formatting the hard disk is out, as also
returning 43 when the value of i is 5 is not possible unless you violate the
standard.
-----Original Message-----
From: Linus Torvalds [mailto:torvalds@transmeta.com]
Think about a basic C (and C++) expression:
++i + ++i
What does the C standard say about the above?
Right. It has undefined behavior. It can return 42. It can format your
harddisk. And the compiler is still strictly conforming, and yes, you get
the occasional "bug-report" about it, but everybody agrees that it _is_
undefined behaviour, and everybody even agrees on _why_ it is undefined
behaviour, and there is really no problem.