sequence point

R

Richard Bos

This is not a question. Here I found a good article that discusses
sequence point in details:

http://www.embedded.com/shared/printableArticle.jhtml?articleID=9900661

It's not bad (I've seen much worse), but the situation is worse than
that writer seems to think. The code he discusses doesn't just invoke
unspecified behaviour because of order of evaluation issues, it actually
invokes full-blown undefined behaviour, because it modifies an object
_and_ reads it for another purpose, between sequence points. This means
that it cannot just call the function with unexpected values, it can
call the function with random values, with trap representations, not
call it at all, or print the lyrics to the Hedgehog Song and then abort.
Or just abort on a bus error without printing the Hedgehog Song, which
is a plausible effect of such code on suitable hardware, where the
arguments are evaluated in parallel.

Richard
 
T

tigervamp

Richard said:
http://www.embedded.com/shared/printableArticle.jhtml?articleID=9900661

It's not bad (I've seen much worse), but the situation is worse than
that writer seems to think. The code he discusses doesn't just invoke
unspecified behaviour because of order of evaluation issues, it actually
invokes full-blown undefined behaviour, because it modifies an object
_and_ reads it for another purpose, between sequence points. This means
that it cannot just call the function with unexpected values, it can
call the function with random values, with trap representations, not
call it at all, or print the lyrics to the Hedgehog Song and then abort.
Or just abort on a bus error without printing the Hedgehog Song, which
is a plausible effect of such code on suitable hardware, where the
arguments are evaluated in parallel.

Richard

I actually thought the article was pretty well written. From what I
could tell, the author points out what is undefined behavior and does a
decent job of explaining why it is undefined. Can you provide a
specific example of where the article is misleading, maybe I missed
something.

Rob Gamble
 
O

Old Wolf

Richard said:
http://www.embedded.com/shared/printableArticle.jhtml?articleID=9900661

It's not bad (I've seen much worse), but the situation is worse
than that writer seems to think. The code he discusses doesn't
just invoke unspecified behaviour because of order of evaluation
issues, it actually invokes full-blown undefined behaviour

The section you read was an earlier incorrect article by him,
and the current article is quoting the old article in order to
go on and correct it. The author should have been clearer about this.
 
R

Richard Bos

tigervamp said:
I actually thought the article was pretty well written.

Well, I certainly didn't think it was bad, and the information is
correct, if incomplete, but it looks like Old Wolf is right and the
article is confusingly laid out.
From what I
could tell, the author points out what is undefined behavior and does a
decent job of explaining why it is undefined. Can you provide a
specific example of where the article is misleading, maybe I missed
something.

From the first part of the article, it's easy to get the impression that
the author thinks UB can only lead to unexpected values. It can actually
lead to crashes, or worse, munged data.

Richard
 

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

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top