Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C - goto a label that located in an external file

Tags:

c

extern

label

Say I got 2 C source files A.c, B.c.

A.c contains a label, that I want to just to from the module B.c.

A.c contains only 1 function:

int f() {
   // some commands
   aLabel:
   // some more commands
   return 1;
}

B.c also contains only 1 function:

extern aLabel;

int g() {
  // do some stuff
  goto aLabel;
}

Obviously these 2 files are linked together to a final .exe file.

How do I jump to an external label?

Thanks in advance.

like image 490
Matt Walst Avatar asked Oct 20 '25 14:10

Matt Walst


1 Answers

goto is always local to a function, you cannot jump between functions using goto. To do non-local jumps take a look a setjmp / longjmp C functions.

like image 118
ouah Avatar answered Oct 23 '25 03:10

ouah



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!