This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: y = (++x) + (++x)


On Fri, 18 Aug 2000, Michael Meissner wrote:

> On Fri, Aug 18, 2000 at 07:31:29PM +0200, Marcus Meissner wrote:
> > On Thu, Aug 17, 2000 at 10:12:35PM -0400, Michael Meissner wrote:
> > > On Fri, Aug 18, 2000 at 12:21:25PM +1100, Andrey Panov wrote:
> > > >   y = (++x) + (++x);                                                            
> > > > It produces output y = 6, x = 3, while one can expect y = 5, x = 3.
> > 
> > > Actually you can't expect y to be 5 or x to be 3.  It is undefined behavior if
> > > you modify the same variable twice (or reference a variable which has been
> > > modified) without a sequence point occuring between the two operations.
> > 
> > What about gcc detecting this and spitting out a warning or error?
> 
> A warning would be useful, since people keep tripping over this.  I suspect you
> have to do in the front end processing for each front end.

As in Michael Meeks's patch from two years ago?

http://gcc.gnu.org/ml/gcc-patches/1998-06/msg00316.html
http://gcc.gnu.org/ml/gcc-patches/1998-07/msg00180.html
http://gcc.gnu.org/ml/gcc-patches/1998-07/msg00182.html

-- 
Joseph S. Myers
jsm28@cam.ac.uk


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]