| March 5, 2009 8:00 PM PST | |
Manually allocate a jump buffer to ensure that it has adequate space to accommodate sufficient pointers for Itanium® architecture.
When using a non-ANSI-defined jmp_buf data type, code might allocate its own jump buffer, which might have a size valid for existing 32-bit Intel® architecture code, but not for Itanium architecture-based code. In the following line of code, enough space is allocated in the buffer for 16 pointers in the 32-bit Intel architecture, but only enough for eight pointers in the 64-bit architecture:
DWORD my_jmpbuf[16]
When using setjmp and longjmp, use the ANSI-defined jmp_buf data type. Note that setjmp saves context into the jmp_buf buffer, which is used later by longjmp. You therefore need to examine the jump buffer size to ensure that it is adequate. The following example shows how the code given in the "Challenge" section could be modified to allocate appropriate the appropriate space for the jump buffer:
jmp_buf my_jmpbuf;
By using jmp_buf, the code ensures that enough space is allocated for the jump buffer, regardless of whether it is compiled for the 32-bit Intel architecture or the Itanium processor. This specific case follows the general rule that it is best not to hard-code data when a system-defined feature can be used instead.
For more complete information about compiler optimizations, see our Optimization Notice.

