clanguage-lawyerfile-descriptorsetjmp

setjmp/longjmp and the state of open files


The C standard says that

All accessible objects have values, and all other components of the abstract machine218) have state, as of the time the longjmp function was called, except that the values of objects of automatic storage duration that are local to the function containing the invocation of the corresponding setjmp macro that do not have volatile-qualified type and have been changed between the setjmp invocation and longjmp call are indeterminate."

218) This includes, but is not limited to, the floating-point status flags and the state of open files.

(emphasis added)

What is the goal of this requirement, and how do implementations deal with it?


Solution

  • It says "as of the time the longjmp function was called", not setjmp, so the requirement is simply to not save/restore too much state, which is easy. (I had to re-read this quite a few times to notice this...)