public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: David Brown <david@westcontrol.com>
To: gcc-help@gcc.gnu.org
Subject: Re: compile with gcc option -O0 or -O
Date: Fri, 16 Sep 2011 07:10:00 -0000	[thread overview]
Message-ID: <j4usou$v7p$1@dough.gmane.org> (raw)
In-Reply-To: <mcrobyl6o4f.fsf@coign.corp.google.com>

On 16/09/2011 07:40, Ian Lance Taylor wrote:
> zou wonder<wonder.zou@gmail.com>  writes:
>
>> but one weird problem is that the following codes compiled with option -O0
>
> You need to show us a small complete self-contained example.
>
> Normally a program which works at -O0 and fails at -O1 has an
> uninitialized variable somewhere.
>
> Ian
>

Another common cause is aliasing - using pointer casts to access the 
same data in different ways.

And (especially if this is embedded programming), also check for missing 
"volatile" qualifiers.

Compile your code with lots of warnings - that will help spot mistakes. 
  The flags I often use are:

-Wall
-Wextra
-Winit-self
-Wmissing-include-dirs
-Wunused
-Wstrict-overflow
-Wfloat-equal
-Wundef
-Wunsafe-loop-optimizations
-Wpointer-arith
-Wcast-qual
-Wcast-align
-Wwrite-strings
-Wlogical-op
-Wmissing-declarations
-Wmissing-noreturn
-Wmissing-format-attribute
-Winline
-Wnested-externs
-Wdisabled-optimization
-Wunsafe-loop-optimizations
-Wpadded
-Wunreachable-code
-Wmissing-prototypes
-Wredundant-decls
-Wcast-qual
-Wcast-align
-Wpointer-arith
-Wnested-externs
-Wno-multichar




  reply	other threads:[~2011-09-16  7:10 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-16  5:04 zou wonder
2011-09-16  5:41 ` Ian Lance Taylor
2011-09-16  7:10   ` David Brown [this message]
2011-09-16  7:54     ` Miles Bader
2011-09-16  9:21       ` David Brown
2011-09-16 10:06         ` Miles Bader
2011-09-16 10:35           ` David Brown
2011-09-16  8:27     ` Jeffrey Walton
     [not found]   ` <CAOXjUBzK0snvjNcpi8D3mK5dmXwzH62XXETyjv+4f6S+LDmXyQ@mail.gmail.com>
     [not found]     ` <CAOXjUBwW2ghmfsF1OA5DY7hZOz-43r22biSG60VyWaviFau_-Q@mail.gmail.com>
     [not found]       ` <mcrfwjx6lrk.fsf@coign.corp.google.com>
2011-09-16  9:12         ` zou wonder
2011-09-16  9:32           ` David Brown
2011-09-16  9:47           ` Jonathan Wakely
2011-09-19  9:57             ` zou wonder
2011-09-19 10:32               ` David Brown
2011-09-21  2:18               ` zou wonder

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='j4usou$v7p$1@dough.gmane.org' \
    --to=david@westcontrol.com \
    --cc=gcc-help@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).