Matt Walst
Matt Walst

Reputation: 49

C - goto a label that located in an external file

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.

Upvotes: 4

Views: 2327

Answers (1)

ouah
ouah

Reputation: 145829

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.

Upvotes: 5

Related Questions