Ne dis pas de conneries... on ne peut pas sortir d'une fonction avec un goto. On parle pas de BASIC là. Il y a longjmp (bien dangereux) pour sauter dans une autre fonction comme un porc.
Exemple.
$ cat test_goto.c
void fonction_b(void) {
probleme_en_vue:
printf("probleme_en_vue...\n");
}
void fonction_a(void) {
printf("fonction_a\n");
goto suite_a;
printf("code mort\n");
suite_a:
printf("suite_a\n");
goto probleme_en_vue;
printf("code mort 2\n");
}
int main(int argc, char *argv[]) {
fonction_a();
}
$ gcc -o test_goto test_goto.c
test_goto.c: In function `fonction_a':
test_goto.c:13: error: label `probleme_en_vue' used but not defined
$
[^] # Re: Hmm :/
Posté par Colin Leroy (site web personnel) . En réponse au journal Entretient du noyau Linux. Évalué à 4.
$ cat test_goto.c void fonction_b(void) { probleme_en_vue: printf("probleme_en_vue...\n"); } void fonction_a(void) { printf("fonction_a\n"); goto suite_a; printf("code mort\n"); suite_a: printf("suite_a\n"); goto probleme_en_vue; printf("code mort 2\n"); } int main(int argc, char *argv[]) { fonction_a(); } $ gcc -o test_goto test_goto.c test_goto.c: In function `fonction_a': test_goto.c:13: error: label `probleme_en_vue' used but not defined $