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

Popular posts from this blog

Retrieving ETA (estimated time of arrival) with Google Distance Matrix API and public transit as transport mode -

javascript - Confirm a form & display message if form is valid with JQuery -

ionic framework - Meteor - Error: Failed to execute 'insertBefore' on 'Node' -