# Introduction
In C programming language, we use `goto` to jump to a specific location **within** the same function.
When we want to jump to a location that is in **another** function, we can use `setjump` and `longjump` to accomplish that.
The basic idea of is that, we use `setjump` function to mark the place we want to jump to, and use `longjump` function to jump. Here is a simple example:
# Example
``` c
#include <setjmp.h>
#include <stdio.h>
jmp_buf buf;
void foo()
{
printf("foo: begin\n");
/* Jump to bar */
longjmp(buf, 0);
/* Won't reach here */
printf("foo: end\n");
}
void bar()
{
printf("bar: begin\n");
/* Set jmp_buf to jump here */
if (setjmp(buf) == 0)
return;
printf("bar: end\n");
}
int main(int argc, char *argv[])
{
bar();
foo();
return 0;
}
```
Compile and run:
```
$ gcc setjmp.c -o setjmp
$ ./setjmp
bar: begin
foo: begin
bar: end
```