Mail Archives: djgpp/1998/06/23/22:46:01
Hans-Bernhard Broeker wrote:
>
> > The optimization flag -O will catch more mistakes?
>
> Sort of. '-Wall' alone won't catch all problems, since the compiler in
> non-optimizing mode won't even look at the source closely enough to notice
> them. To cite the gcc docs:
>
> `-Wuninitialized'
> An automatic variable is used without first being initialized.
>
> These warnings are possible only in optimizing compilation,
> because they require data flow information that is computed only
> when optimizing. If you don't specify `-O', you simply won't get
> these warnings.
>
> So yes, for ultra-picky gcc operation, you'll need '-Wall -O'.
Not just ultra-picky... imagine the following very common mistake:
#include <stdio.h>
int main( void )
{
char *str;
printf( "Type your name: " );
gets( str ); /* str is uninitialized ==> crash */
printf( "Your name is %s.\n", str );
return 0;
}
'-Wall' alone won't catch this error, nor similar but more complex
ones. Adding '-O' has saved me from crashes or other erroneous behavior
so many times now that I've lost count. :-)
P.S.: I know gets() is bad; it's just an example.
--
---------------------------------------------------------------------
| John M. Aldrich | "Sin lies only in hurting other |
| aka Fighteer I | people unnecessarily. All other |
| mailto:fighteer AT cs DOT com | 'sins' are invented nonsense." |
| http://www.cs.com/fighteer | - Lazarus Long |
---------------------------------------------------------------------
- Raw text -