Setjmp standard defined notes

ISO / IEC 9899: 1999

7.13.1.1 mask setjmp

Environmental limits 4 A call to the setjmp macro will appear only in one of the following contexts: - the entire control expression of the expression of choice or iteration; - one operand is a relational or equality operator with another operand an integer is a constant expression, while the resulting expression is complete control over the expression of the expression of choice or iteration; - the operand of the unary! the operator with the resulting expression is the full control expression of the choice or iteration expression; or - the entire expression of the expression (possibly void).

Thus, the only options for using setjmp are as follows:

if (setjmp(buf)) while (setjmp(buf)) for (;; setjmp(buf)) if (setjmp(buf) == 0) while (setjmp(buf) == 0) for (;; setjmp(buf) == 0) if (!setjmp(buf)) while (!setjmp(buf)) for (;; !setjmp(buf)) setjmp(buf); (void)setjmp(buf); 

And we cannot use these statements:

 int foo = setjmp(buf); foo = setjmp(buf); 

Right? What do they mean by an iterative expression? Last for loop statement?

+4
source share
2 answers

No you cannot use

 int foo = setjmp(buf); foo = setjmp(buf); 

The reason for the later (assignment) is probably because the assignment is an expression that can have more than just an identifier on the left side. If the left side is an lvalue expression, the standard does not impose the order in which the subexpressions are evaluated. Therefore, if you have

 int* f(void); *f() = setjmp(buf); 

*f() and setjmp(buf) can be evaluated in any order. Since setjmp takes a snapshot of the actual state of the abstract state of the machine, the semantics of both orders will be completely different.

For the first line (initialization) this problem does not occur, I think. Therefore, I suggest that this could be added as actual use. But it will need to be thoroughly discussed if there are no border cases that still require evaluation from the left.

(Eric has already answered for the approval of the choice.)

+3
source

Selection operators if (including if…else ) and switch . Iteration operators: while , do…while and for .

+2
source

All Articles