Is it good programming practice to use setjmp and longjmp in C?

前端 未结 8 1895
误落风尘
误落风尘 2021-02-07 10:28

I\'m a C++ programmer and used to OO languages with good exception handling.

From what I can understand, setjmp and longjmp are essentially a c-style way to propogate ex

8条回答
  •  长情又很酷
    2021-02-07 11:26

    setjmp and longjmp are macros used to bypass normal function call and return flow.
    The setjmp saves the calling env to be used by longjmp
    Use of these macros correctly is really hard and you can easily end up with undefined behavior.
    Because of this, it is mandated for example to restrict longjmp to 1 level of signal handler (best actually to not be called at all).
    In critical systems it is required not to be used at all.

提交回复
热议问题