在 MacOS X 10.6.2 上,标题 <setjmp.h> 最终使用 <i386/setjmp.h>,并在其中显示:
#if defined(__x86_64__)
/*
* _JBLEN is number of ints required to save the following:
* rflags, rip, rbp, rsp, rbx, r12, r13, r14, r15... these are 8 bytes each
* mxcsr, fp control word, sigmask... these are 4 bytes each
* add 16 ints for future expansion needs...
*/
#define _JBLEN ((9 * 2) + 3 + 16)
typedef int jmp_buf[_JBLEN];
typedef int sigjmp_buf[_JBLEN + 1];
#else
/*
* _JBLEN is number of ints required to save the following:
* eax, ebx, ecx, edx, edi, esi, ebp, esp, ss, eflags, eip,
* cs, de, es, fs, gs == 16 ints
* onstack, mask = 2 ints
*/
#define _JBLEN (18)
typedef int jmp_buf[_JBLEN];
typedef int sigjmp_buf[_JBLEN + 1];
#endif
您可能会在 Linux 上找到类似的要求 - jmp_buf 包含足够的信息来存储必要的状态。而且,要使用它,你真的不需要知道它包含什么;您需要做的就是相信实施者做对了。如果您想更改实现,那么您当然需要了解它。
请注意,setjmp 和 longjmp 是非常特定于机器的。阅读 Plauger 的“The Standard C Library”,了解实施它们所涉及的一些问题。更现代的芯片很难真正很好地实现。