News for hackers. Stuff that matters.
Re:Let's write a setjmp by comex on Sunday February 12, 2023 @02:33PM (#34766044)
> I am not aware of any such "longjmp" implementation.

Clang on Windows behaves this way! That is, when targeting the Visual C++ runtime, as opposed to MinGW.

With the Visual C++ toolchain and runtime, longjmp behaves like a C++ exception throw and goes through a whole stack unwinding routine, unlike on Unix (and MinGW) where it just sets a few registers and branches. This has the downside of being much slower, but the benefit that longjmp will run destructors of C++ local variables as it unwinds (as well as SEH `__finally` blocks), making it less of a footgun in C++ code.

Visual C++ itself doesn't support GCC extensions like `__attribute__((cleanup))`, but these days Clang is highly compatible with Visual C++ while also supporting GCC extensions.

There are no comments on this comment yet.