Optimization error?

Gregory Smith greg at utcsri.UUCP
Mon Apr 21 13:56:36 AEST 1986


In article <3109 at reed.UUCP> joey at reed.UUCP (Joe Pruett) writes:
>I contend that if the compiler could figure out that flag could
>get set to 1, then it should also figure out that flag might not
>bet set to anything, and at least issue a warning, but it should
>not optimize the expression away.
>
>Is this a bug, or a misfeature, or an inherent gotcha with fancy
>optimization?

I would say that a run-time bug in your code has propogated its way
into compile-time - an inherent gotcha.  To determine in general that
the flag may not be set is probably (?) similar to the halting problem
- it can't be done (* In General *) so it will only be detected for
simple cases. Lint apparently looks at the textual order of operations
 - the following draws a warning:

	int i,j;
	for(i=1;i<=2;++i){
		if(i==2) printf("j = %d\n", j );
		j = 123;
	}

Lint will say that j is used before it is set. An example can be set up
with goto's { goto b; a: use(j); return; b: j=0; goto a;}. In this
case it is more obvious that the code is ok but Lint will still warn.
-- 
"If you aren't making any mistakes, you aren't doing anything".
----------------------------------------------------------------------
Greg Smith     University of Toronto      UUCP: ..utzoo!utcsri!greg



More information about the Comp.lang.c mailing list