delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/06/23/22:46:01

From: "John M. Aldrich" <fighteer AT cs DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Program Crashes!!! Please help! Memory errors!!!
Date: Tue, 23 Jun 1998 22:33:16 -0400
Organization: Two pounds of chaos and a pinch of salt.
Lines: 44
Message-ID: <3590656C.C5EFE3E8@cs.com>
References: <199806231101 DOT NAA05619 AT acp3bf DOT physik DOT rwth-aachen DOT de>
NNTP-Posting-Host: ppp122.cs.net
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019