c++ - GOTO instruction in recursive functions -
if use goto instruction inside recursive function (wanting exit function before finishes naturally) stack freed automatically or not?
consider below program, in there goto statement final return. free stack seeing goto. though use goto inside functions stack maintained such.
#include <stdio.h> int fact(int a) { if(a==1) goto a; return a*fact(a-1); a: return a; } int main() { printf("%d",fact(10)); } you can't jump 1 function using goto in standard c++. $6.6.4/1 of c++ language standard
the goto statement unconditionally transfers control statement labeled identifier. identifier shall label (6.1) located in current function.
...or in standard c. $6.8.6.1/1 of c language standard
the identifier in goto statement shall name label located somewhere in enclosing function. goto statement shall not jump outside scope of identifier having variably modified type inside scope of identifier.
Comments
Post a Comment