在C语言中,setjump()和longjump()函数的翻译如下:

在C语言中,setjump()和longjump()函数的翻译如下:

在这个部分,我们将看到C语言中的setjump和longjump是什么。setjump()和longjump()位于setjmp.h库中。这两个函数的语法如下所示。

setjump(jmp_buf buf) : uses buf to store current position and returns 0.
longjump(jmp_buf buf, i) : Go back to place pointed by buf and return i.

登录后复制

These are used in C for exception handling. The setjump() can be used as try block, and longjump() can be used as throw statement. The longjump() transfers control the pointe which is pointed by setjump().

Here we will see how to print a number 100 times without using recursion, loop, or macro expansion. Here we will use the setjump() and longjump() functions to do that.

Example

#include
#include
jmp_buf buf;
main() {
int x = 1;
setjmp(buf); //set the jump position using buf
printf(“5”); // Prints a number
x++;
if (x

上一篇 Python程序用于测试字符串是否只包含数字和字母
下一篇 如何调试和记录 PHP OPcache 问题
泡泡

泡泡

做最好的知识分享 CSDN云计算领域优质创作者,2022新星计划算法赛道实力新星 算法/云计算/云原生

本月创作热力图