if (e1) return e2; [else] s1;

Kral braun at drivax.UUCP
Thu Mar 29 02:19:01 AEST 1990


In article <2637 at quiche.cs.mcgill.ca> utility at quiche.cs.mcgill.ca (Ronald BODKIN) writes:
>Is this reallly a clearer and neater way of coding:
>int foo()
>{
>	int ret;
>	if (cond1) {
>		/* do stuff */
>		ret=1;
>	}
>	else {
>		/* do other stuff */
>		ret=2;
>	}
>	return ret;
>}

I say yes.  In addition, it's easier to modify (say you want to do some further
processing before you return), and it's easier to debug with a debugger, as
there is only one place you have to break to stop the return.

-- 
kral 	408/647-6112			...amdahl!drivax!braun
"To surrender is to remain in the hands of barbarians for the rest of my life;
 To fight is to leave my bones exposed in the desert waste" 
		- ancient chinese poem



More information about the Comp.lang.c mailing list