* James Kanze:
> On Nov 21, 2:18 pm, "Alf P. Steinbach" <al...@start.no> wrote:
>> * Kai-Uwe Bux:
>>> James Kanze wrote:
>>>> On Nov 21, 6:52 am, Kai-Uwe Bux <jkherci...@gmx.net> wrote:
>>>>> simudr...@gmail.com wrote:
>>>>>> //hi maybe helpful others can look at this code and
>>>>>> //tell me why the class code won't behave like
>>>>>> //intrinsic types with post and pre increment
>>>>> [snip]
>>>>>> IntWrapper test1 = test + test++;
>>>>>> int test2 = i + i++;
>>>>>> //test1 should be the same as test2 but they are not
>>>>> As far as I can see you have unspecified behavior according to
>>>>> clause [5/4] of the standard.
>>>> Not unspecified. Undefined. At least in the second line.
>
>>> Well, I don't see a variable that has its value modified
>>> twice between sequence points. So it must be the condition
>
>>> "Furthermore, the prior value shall be accessed only to
>>> determine the value to be stored."
>
>>> and I have to admit that I never have been able to figure
>>> out the meaning of this sentence.
>
>> It's probably intended to mean that if an epression modifies a
>> variable, the expression shall not use the prior value of the
>> variable for anything else than the computation of the new
>> value, e.g. not displayed or stored elsewhere.
>
> The prior value may not be accessed, period, other than to
> determine the new value. You don't have to display or store it
> elsewhere---you just have to use it in an expression. (Of
> course, I'm not sure that means anything in practice. But it's
> what the standard says.)
Exactly how do you think that's different from what I wrote?
>> That way the compiler can optimize prematurely to its heart
>> content without ensuring that the value is consistent during
>> the evaluation of the expression. But as the incorrect
>> examples in the standard demonstrate,
>
> Which "incorrect examples"? The only incorrection I see in the
> examples is the use of the word "unspecified" rather than
> "undefined" in the comments. The preceding (normative) text
> makes it quite clear, however, that the behavior in the examples
> is undefined. (There are other cases where it isn't so clear,
> of course.)
Again, how is that different from what I wrote?
>> this part of the standard is bungled, and one must therefore
>> ignore it & apply common sense instead of the literal wording.
>
> That's your opinion, and it isn't shared by the experts (unless
> you mean something different by "bungled" than I understand).
It's being corrected in C++0x.
And I remind you that you have participated in extended discussions in
e.g. comp.std.c++ about what the wording means, where you have taken on
minority positions.
Your reference to unspecified "experts" is therefore (a) evidently
incorrect, and (b) fallacious anyway.
> Generally speaking, it is recognized that the model used to
> express the constraints here is not ideal. The C committee
> discussed the issues when updating the C standard (resulting in
> C99). The consensus among the experts at the time was that
> while not the best, the current wording was sufficient for what
> was wanted, and that a rewrite wasn't necessary. (The rules
> here are taken verbatim from the C standard.)
>
> Of course, the rules don't address threading issues. Since the
> C++ standard is addressing threading, this section does require
> rework, and is the subject of a complete rewrite. In
> collaboration with the C committee---the intent is that whatever
> we rewrite will be acceptable to them, and integrated into the
> next version of the C standard as well.
You may of course, by association, include yourself in the panel of
people rewriting this stuff, if you're participating in the committee
(do you, still?), and you may attribute the changes to anything vaguely
associated. Let the associations run wild.
>> Common sense is to not use side effects in sub-expressions.
>
> Ideally: each statement does one thing, and one thing only. A
> flow control statement doesn't modify program state, and a
> statement which modifies an object doesn't modify any other
> program state, nor affect flow control.
>
> Practically, there are exceptions. But they should be very
> rare (and almost always concern modifying state in a flow
> control statement, and not modifying two different objects in a
> single statement).
>
> Hopefully, we've gotten past the days when people thought that
> things like:
> while ( *p ++ = *q ++ ) ;
> was acceptable in production code.
It's an idiom, presented in the first version of "The C Programming
Language" by Kernighan & Ritchie.
Cheers, & hth.,
- Alf
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?