code in C( is it correct)

A

Alf P. Steinbach

* Alf P. Steinbach:
* Jerry Coffin:

I can't find fault with your logic here,

Well, "Garbage In Garbage Out" (no offense meant but it applies here), sorry, I
should have checked.

Your quote of §5/4 doesn't include the part where it says it's Undefined
Behavior (last sentence), and you state that it doesn't include that phrasing,
and I just assumed that that was correct.

However, that description of §5/4 isn't correct, it says "the behavior is
undefined".

but at the same time this rule
cannot be a diagnosable one (in general).

And so I suggest (1) checking whether C++0x has changed this, and if
not, (2) whether there is an Active Issue, and if not, (3) posting in
[comp.std.c++].

Anyway, it would be nice to know the result of that... ;-)

Results above. :)

It's explicitly UB, and therefore formally not a diagnosable rule.



Cheers & hth.,

- Alf
 
J

James Kanze

I'm afraid that's not really true. According to §5/4:
Between the previous and next sequence point a scalar
object shall have its stored value modified at most
once by the evaluation of an expression.
And according to 1.4/1:
The set of diagnosable rules consists of all syntactic
and semantic rules in this International Standard
except for those rules containing an explicit notation
that ?no diagnostic is required? or which are described
as resulting in ?undefined behavior.?
The requirement in §5.4 certainly sounds like a semantic rule
to me, and it doesn't seem to include either of the specified
phrases.

You quoted it out of context. Then entire paragraph (§5/4) is:

Except where noted, the order of evaluation of operands
of individual operators and subexpressions of individual
expressions, and the order in which side effects take
place, is unspecified. Between the previous and next
sequence point a scalar object shall have its stored
value modified at most once by the evaluation of an
expression. Furthermore, the prior value shall be
accessed only to determine the value to be stored. The
requirements of this paragraph shall be met for each
allowable ordering of the subexpressions of a full
expression; otherwise the behavior is undefined.

The "otherwise the behavior is undefined" certainly seems to
correspond to "described as resulting in `undefined behavior'"
to me. (In practice, of course, it's not diagnosable except in
the simplest cases; e.g "*p = (++*q)" is only undefined behavior
if p and q are equal.)
 
J

Jerry Coffin

[ ... ]
Except where noted, the order of evaluation of operands
of individual operators and subexpressions of individual
expressions, and the order in which side effects take
place, is unspecified. Between the previous and next
sequence point a scalar object shall have its stored
value modified at most once by the evaluation of an
expression. Furthermore, the prior value shall be
accessed only to determine the value to be stored. The
requirements of this paragraph shall be met for each
allowable ordering of the subexpressions of a full
expression; otherwise the behavior is undefined.

The "otherwise the behavior is undefined" certainly seems to
correspond to "described as resulting in `undefined behavior'"
to me.

Yup -- I saw where it started to talk about the prior value being
accessed only to determine the value to be stored, and thought the
previous discussion was closed, and never noticed that last sentence.

My apologies to all for a thoroughly flawed and incorrect analysis --
what I said was definitely wrong.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,905
Latest member
Kristy_Poole

Latest Threads

Top