I wrote the routine below to test some code in one of our
applications. This snippet exactly mirrors what is happening in our
real code. It was compiled on a sun-4 ultra platfrom using SC5.0 under
Solaris 5.6. If I pass the integer value of 2 as the first arguement
then control falls through the switch statement, and out of the
routine without explicitly returning any value. The compiler does not
report this as either a warning or an error. So far I have not been
unable to find anywhere in the documentation that specifies what the
return value from a routine will be if it is not explicitly given a
value to return. In my test, I wrote a short main to pass the values
(1,1), (1,2), and(2,1) to switchTest(int, int). The first 2 calls
returned the predictable results of TRUE and FALSE. The third call
also returned a FALSE, but that does not satisfy me that the return
value will always be FALSE.
bool switchTest(int num, int num2)
{
switch(num) {
case 1:
switch(num2) {
case 1:
printf("CASE 1: Num = %d, Num2 = %d\n", num, num2);
return(TRUE);
break;
default:
printf("DEFAULT CASE: Num = %d, Num2 = %d\n", num, num2);
return(FALSE);
}
}
Does anybody have the precise information on what the behaviour forQuote:}
this compiler is defined to be for this situation?
Nick