New const function detection code and infinite loops.

Joern Rennecke amylaar@cygnus.co.uk
Tue Aug 31 23:20:00 GMT 1999


> Well and for example following function:
> int funct(int b)
> {
>   while(b&1) b+=2;
>   return b;
> }
> main()
> { 
>   funct(1);
> }
> despite the fact, that function is complette nonsence, it still contains
> infinite loop (for certain input values), but will be marked as const by
> the detection code. So this program will terminate. Maybe this is ANSI-C
> conforming, but I don't believe so.

Since you declared b as int, the result of the overflow is undefined.
If you had used 'unsigned int' , the program would be well-defined
(to not terminate).



More information about the Gcc mailing list