Topic: dynamic variant behavior" in the standard


Author: "Me" <anti_spam_email2003@yahoo.com>
Date: Tue, 2 Jan 2007 12:22:25 CST
Raw View
Here is one issue I don't believe the C++ covers one way or the other,
something I term "dynamic variant behavior" (for lack of a better term)
to mean everywhere that the standard lists as implementation defined or
unspecified behavior, a conforming implementation is (I believe)
technically allowed to make a list of orthogonal rules on what to do
and randomly pick between one of them (even at runtime) as opposed to
using a single strategy and applying it everywhere. For a concrete
example of this:

int a;
int dec() { return --a; }
int inc() { return ++a; }
template<int> int spin() { return dec() + inc(); }


So depending on the order of evaluation, spin() can return 1 or -1.
"Everybody knows that":

spin<0>() - spin<1>()

isn't guaranteed to evaluate to 0. But what about this case:

spin<0>() - spin<0>();

Since evaluation order is unspecified, I believe a conforming C++
implementation is allowed to transform spin into:

template<int>
int spin()
{
 int i, d;
 if (coin_toss())
  i = inc(), d = dec();
 else
  d = dec(), i = inc();
 return i + d;
}

So it can pick a random permutation of evaluation order each time the
function is called.

---
[ 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.comeaucomputing.com/csc/faq.html                      ]





Author: pete@versatilecoding.com (Pete Becker)
Date: Tue, 2 Jan 2007 20:59:39 GMT
Raw View
Me wrote:
> Here is one issue I don't believe the C++ covers one way or the other,
> something I term "dynamic variant behavior" (for lack of a better term)
> to mean everywhere that the standard lists as implementation defined or
> unspecified behavior, a conforming implementation is (I believe)
> technically allowed to make a list of orthogonal rules on what to do
> and randomly pick between one of them (even at runtime) as opposed to
> using a single strategy and applying it everywhere.

That's correct. When the standard doesn't impose requirements, you can't
look to the standard to decide what an implementation should do. If you
don't like what your compiler does, talk to the vendor.

--

 -- Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com)
Author of "The Standard C++ Library Extensions: a Tutorial and
Reference." (www.petebecker.com/tr1book)

---
[ 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.comeaucomputing.com/csc/faq.html                      ]