Wednesday, January 21, 2015

Comment on GotW #94 Solution: AAA Style (Almost Always Auto) by Answer: How to implement classic sorting algorithms in modern C++? #fix #development #computers | IT Info

 
 

Comment on A quick poll about order of evaluation… by David Thornley

Suppose we were doing this with a user-defined type, so instead of
  v[i++]=i++;  
we had
  v.operator[](i.operator++())..operator=(i.operator++());  
In this case, we have unspecified behavior (feel free to correct me if I’m wrong) because the order of function calls isn’t completely specified. There’s advice to make UDTs that do arithmetic work like ints, so it seems reasonable to me to make the ints work like UDTs here. That’s why I voted for “unspecified”.
I don’t want to specify a behavior here, because that’s more stuff I’d have to learn to read the code. Ideally, I’d like code that requires complicated rules to understand, and can easily be written less ambiguously, to be a genuine error. C++ has enough readability problems, for a variety of reasons.
I’ve become less fond of undefined behavior since gcc started optimizing it out so aggressively. In cases like accessing outside the bounds of an array, I think it appropriate, since the likely outcomes (exception, wrong answer) are sufficiently different from one another. In this case, we’re going to get some reasonably valid result under any reasonable interpretation of what the computer is likely to do, so unspecified.

Read More »

Comment on GotW #94 Solution: AAA Style (Almost Always Auto) by Answer: How to implement classic sorting algorithms in modern C++? #fix #development #computers | IT Info

[…] Sutter’s “Almost Always Auto” and Scott Meyers’s “Prefer auto to specific type declarations” recommendation, […]

Read More »
 
 

No comments:

Post a Comment