From -1114728655851687354
X-Google-Thread: f78e5,174aa7b34b06a51
X-Google-Attributes: gidf78e5,public
X-Google-Language: ENGLISH,ASCII-7-bit
Path: g2news1.google.com!news3.google.com!news.glorb.com!newsgate.cistron.nl!skynet.be!peer-uk.news.demon.net!kibo.news.demon.net!news.demon.co.uk!demon!stump.algebra.com!devnull
From: bop@gmb.dk ("Bo Persson")
Newsgroups: comp.std.c++
Subject: Re: Is this really unspecified behavior?
Date: Sat, 10 Dec 2005 22:22:37 GMT
Lines: 84
Sender: mail2news@demon.net
Approved: fjh@cs.mu.oz.au (Fergus Henderson , moderator of comp.std.c++)
Message-ID: <3vvv5mF180o2gU1@individual.net>
References: <1132629737.664847.151630@o13g2000cwo.googlegroups.com> <1132662585.882464.24110@f14g2000cwb.googlegroups.com> <E1EeZw5-0004wI-00@chx400.switch.ch> <XBQgf.150724$zb5.113482@bgtnsc04-news.ops.worldnet.att.net> <1132759176.368850.264850@g43g2000cwa.googlegroups.com> <H1phf.161529$zb5.99785@bgtnsc04-news.ops.worldnet.att.net> <1132933832.802917.153350@g14g2000cwa.googlegroups.com> <1133551647.532929.325730@z14g2000cwz.googlegroups.com> <1133583412.951239.208510@g49g2000cwa.googlegroups.com> <E1EjG <Ir8zAp.s0y@beaver.cs.washington.edu>
NNTP-Posting-Host: news.news.demon.net
X-Trace: news.demon.co.uk 1134253397 24951 158.152.254.254 (10 Dec 2005 22:23:17 GMT)
X-Complaints-To: abuse@demon.net
NNTP-Posting-Date: Sat, 10 Dec 2005 22:23:17 +0000 (UTC)
X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov)
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
X-Priority: 3
X-Orig-X-Trace: individual.net oEYbsrgOGLJI35qbYcaMjg1zgtu26SCDV3jP+l0UwfDLbsmhDZ
X-RFC2646: Format=Flowed; Response
X-Virus-Scanned: amavisd-new at cs.mu.OZ.AU
X-MSMail-Priority: Normal
X-Received: (from fjh@localhost)
	by mulga.cs.mu.OZ.AU (8.12.10+Sun/8.12.9/Submit) id jBAMMbkk021888;
	Sun, 11 Dec 2005 09:22:37 +1100 (EST)
X-Path: comp-std-cpp-robomod!not-for-mail
X-Delivered-To: std-c++@ucar.edu
X-Authentication-Warning: mulga.cs.mu.OZ.AU: fjh set sender to devnull@stump.algebra.com using -f
X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
X-Newsgroups: comp.std.c++
Xref: g2news1.google.com comp.std.c++:2729


"Andrei Alexandrescu (See Website For Email)" 
<SeeWebsiteForEmail@moderncppdesign.com> skrev i meddelandet 
news:Ir8zAp.s0y@beaver.cs.washington.edu...
> Bo Persson wrote:
>> "Ron Natalie" <ron@spamcop.net> skrev i meddelandet
>>>but it's generally not possible to
>>>tell that the functions have untoward effect.
>>>
>>>All it takes is a write to the same ultimate output channel (which
>>>may be unrelated C++ streams) to cause variability in observed 
>>>behavior.
>>>
>>
>>
>> Yes, but should we encourage that kind of coding, by defining its 
>> meaning? I have never felt that I need to write code like
>>
>> i = f(i++, i++);
>>
>> so I don't think it is very productive to spend time specifying 
>> exactly what it means.
>
> Maybe, however, at some point someon might write:
>
> f(a++, b++);
>
> where a and b are references that could alias. In that case, it is 
> very useful to define the behavior of the code. It would be naive to 
> believe that code tripping on unspecified order of execution can 
> only be "obviously dumb" by eye inspection.
>

I would still argue that this is what I call "bad code", and that 
doing the aliasing without noticing it is even worse.  :-)

However, in a previous post you wrote:

>(1) A "programmer willing to optimize" who knows that right-to-left 
>evaluation is algorithmically better AND knows that left-to-right 
>evaluation is guaranteed will introduce named temporary to force 
>right-to-left evaluation. That is the best solution of all, better 
>than the programmer just leaving optimality at the whim of the 
>compiler.

And here I agree, totally!

Right now, I write my code under the assumption that the compiler is 
smart enough to select the proper order - one that is good enough. I 
have argued that in my code there is no advantage for a left-to-right 
order, because I tend not to write code where it matters.

You just made me realize that the "smart enough" compiler, that I 
trust to select a good order, must of course be smart enough to see 
this as well. So, if my code is written without the nasty side 
effects, and without order dependencies, the compiler can use the 
as-if rule and continue to produce the same code for *my* programs.

So, instead of me telling the OP that he can arrange his code better, 
we can both get what we want. He can have his left-to-right order of 
evaluation, and I can still write my code so that it generally doesn't 
matter. In the few cases where it really does matter for me, I can 
rearrange *my* code to evaluate the arguments before the function 
call, in any order I want. Fine with me!

So, specifying the order of evaluation in the Standard might be a good 
idea after all.


Thanks Andrei!


Apologies to Hyman Rosen, for telling you how to write your code.


Bo Persson


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]



