run incorrecly using -O?

Discussion in 'C++' started by Onix, Apr 10, 2008.

  1. Onix

    Onix Guest

    I wrote a program and when compile it with g++ without optimized
    option -O, the final program runs correctly, but if I compile it using
    -O then the final program produced error.

    Is there anything I need to aware when using -O?
     
    Onix, Apr 10, 2008
    #1
    1. Advertising

  2. Onix

    utab Guest

    On Apr 10, 8:45 pm, Onix <> wrote:
    > I wrote a program and when compile it with g++ without optimized
    > option -O, the final program runs correctly, but if I compile it using
    > -O then the final program produced error.
    >
    > Is there anything I need to aware when using -O?


    It is best if you paste some code to comment on?

    Rgds,
     
    utab, Apr 10, 2008
    #2
    1. Advertising

  3. Onix

    red floyd Guest

    Victor Bazarov wrote:
    > Onix wrote:
    >> I wrote a program and when compile it with g++ without optimized
    >> option -O, the final program runs correctly, but if I compile it using
    >> -O then the final program produced error.
    >>
    >> Is there anything I need to aware when using -O?

    >
    > Your program most likely has undefined behaviour which changes if it
    > is compiled (optimized) a bit more than not at all. You need to aware
    > how to debug your program, and spend some time doing that.
    >

    That's not necessarily the case. I dealt with some (C -- not C++) code
    where gcc did some overly aggressive optimizations that led to segfaults
    and bus errors (granted, the code was using ugly constructs, but they
    were well-defined).
     
    red floyd, Apr 11, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. duncan
    Replies:
    2
    Views:
    6,095
  2. Replies:
    2
    Views:
    3,129
  3. Andrea9
    Replies:
    1
    Views:
    340
    Andrea9
    Oct 20, 2006
  4. Replies:
    3
    Views:
    355
    Gabriel Genellina
    Jun 23, 2007
  5. Fa Sidd
    Replies:
    12
    Views:
    217
    ara howard
    Jan 26, 2008
Loading...

Share This Page