News for hackers. Stuff that matters.
Re:Let's write a setjmp by kazinator on Monday February 13, 2023 @01:24PM (#34777818)
The ISO C longjmp has a stupid feature. It takes an argument that is returned to the setjmp caller, but if it is specified as 0, it is rewritten to 1.

It means that a longjmp instruction sequence has to contain an extra conditional check which substitutes a nonzero value for a zero value. Instead of the completely trivial, branch-free instruction sequence it wants to be.

Of all the places where it would be good for C to compensate for a programmer mistake, why do it here? Why can't it just be that the value is the value. If you pass zero to longjmp, your logic breaks; the caller of setjmp gets a zero, and so it looks like a context has just been saved.

Meanwhile, if you perform an input operation on a read/write stream whose most recent operation was output, and you didn't fflush or use a positioning operation, you have undefined behavior.

There are no comments on this comment yet.