setjmp return value as the right-hand side of a assignmentexpression?

T

Tim Rentsch

Kaz Kylheku said:
There are two problems with

x = setjmp(...);

One is surmountable; the other isn't.

The first problem is that if x is a variable with automatic storage
which is not volatile-qualified, then the above constitutes an
instance of modifying a non-volatile auto variable after doing a
setjmp, before the longjmp takes place. The value of such a
variable is indeterminate. (See paragraph in description of
longjmp.)

Right, to satisfy the rule above modifying variables x should be
declared volatile if it is local to this function.
The second problem is that when control returns into the setjmp()
expression for a second time via the longjmp invocation, the
setjmp-time environment (all accessible objects) is being restored.

So, imagine that setjmp is being re-activated by a longjmp and is
restoring the value of x:

x = setjmp(...);

But remember that setjmp is not a function, but a macro. It doesn't
have a sequence point between its restoring actions, and the action
of returning a value. So the above constitutes two modifications of
object x without an intervening sequence point.

Of course there is an intervening sequence point. In order to
get to the longjmp() call, program execution had to proceed past
the point of the assignment, which means there was a sequence
point already passed at the end of the full expression containing
the assignment. Just because longjmp() returns to the middle of
the assignment statement doesn't mean it "erases" that sequence
point, any more than it erases any other intervening sequence
points that have occurred.
 

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,780
Messages
2,569,610
Members
45,255
Latest member
TopCryptoTwitterChannels

Latest Threads

Top