run incorrecly using -O?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Onix

    run incorrecly using -O?

    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?
  • Victor Bazarov

    #2
    Re: run incorrecly using -O?

    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.

    V
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask


    Comment

    • utab

      #3
      Re: run incorrecly using -O?

      On Apr 10, 8:45 pm, Onix <onix.x...@gmai l.comwrote:
      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,

      Comment

      • red floyd

        #4
        Re: run incorrecly using -O?

        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).

        Comment

        • Victor Bazarov

          #5
          Re: run incorrecly using -O?

          red floyd wrote:
          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).
          Right. Compiler/optimizer defects can affect the outcome as well,
          although they are *less likely*. First thing to check is the case
          of uninitialised pointer. But this cannot be concluded with any
          certainty without looking at the code.

          V
          --
          Please remove capital 'A's when replying by e-mail
          I do not respond to top-posted replies, please don't ask


          Comment

          • Victor Bazarov

            #6
            Re: run incorrecly using -O?

            red floyd wrote:
            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).
            Right. Compiler/optimizer defects can affect the outcome as well,
            although they are *less likely*. First thing to check is the case
            of uninitialised pointer. But this cannot be concluded with any
            certainty without looking at the code.

            V
            --
            Please remove capital 'A's when replying by e-mail
            I do not respond to top-posted replies, please don't ask


            Comment

            Working...