Is goto safe?

Tom Markson tom at usblues.UUCP
Wed Jan 17 20:45:35 AEST 1990


I posted this previously, but I don't think it went out.  Apologies if it
did.

Without getting into style issues, is the goto statement in C safe?
For instance, If I do the following, am I guarenteed that no stack
crashes will occur:
	main() {
		{ int i;
		  i=0;
	inside:	  
		  i++;
		  printf("inside:%d\n",i);
		  goto outside;
		}
		{
		  int j;
		  j=0;
	outside:
		  j++;
		  printf("outside: %d\n",j);
		  goto inside;
		}
}

My C compiler (xenix) codes this and it runs.  i and j keep their values.
The .s file indicates that all stack space is allocated at the start of a 
function.  

Question:  Is this always true.  Will it always run as expected with i and j
incrementing from 0 to ...?

Note:  According to K & R, the one restriction to goto is that it must be 
       within a func.  Can I count on this being the only restriction?

Thank you in advance.
-- 
Tom Markson
			...!uunet!usblues!tom
			...!cbmvax!amix!blekko!usblues!tom



More information about the Comp.lang.c mailing list