P
pertheli
I am in a situation where only "goto" seems to be the answer for my
program logic where I have to retry calling some repeated functions.
Can anybody help in the usage of goto and its effect in local
variables, as shown in the stripped code below
void MyClass
rocess(){
int iMaxRetry = 100;
int iRetryCount = 0;
.....
.....
Retry:
iRetryCount++; // counter for retrying
somefunction1();
bool bNewBool = FALSE; // some local variable
char* myVar1 = malloc(100);
CSomeClass myVar2;
if (!somefunction2()){ // if condition is not valid retry
if (iRetryCount < iMaxRetry){
if (myVar1) free(myVar1);
goto Retry; // go back and try again
}
}
.....
.....
}
What is the effect of calling repeated "Retry:" block to the local
variables such as bNewBool, myVar1, myVar2? Are they called again? ie
reinitialised? Is it safe to use? although it seems to be working fine
program logic where I have to retry calling some repeated functions.
Can anybody help in the usage of goto and its effect in local
variables, as shown in the stripped code below
void MyClass
int iMaxRetry = 100;
int iRetryCount = 0;
.....
.....
Retry:
iRetryCount++; // counter for retrying
somefunction1();
bool bNewBool = FALSE; // some local variable
char* myVar1 = malloc(100);
CSomeClass myVar2;
if (!somefunction2()){ // if condition is not valid retry
if (iRetryCount < iMaxRetry){
if (myVar1) free(myVar1);
goto Retry; // go back and try again
}
}
.....
.....
}
What is the effect of calling repeated "Retry:" block to the local
variables such as bNewBool, myVar1, myVar2? Are they called again? ie
reinitialised? Is it safe to use? although it seems to be working fine