Thread: warning: control reaches end of non-void function

  1. #1
    Registered User
    Join Date
    Dec 2004
    Posts
    163

    warning: control reaches end of non-void function

    I got this warning message
    "warning: control reaches end of non-void function"

    May I know exactly what does it mean?

    And what is the difference between the compiling option -O2 and -O3?

    Thanks for your help!

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    I got this warning message
    "warning: control reaches end of non-void function"

    May I know exactly what does it mean?
    Assumably, it means that you have to return a value using the return statement before the end of your function. This does not apply to void functions because a void function does not return a value.
    And what is the difference between the compiling option -O2 and -O3?
    GCC Help: Options That Control Optimization
    Last edited by anonytmouse; 01-29-2005 at 11:17 AM.

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Code:
    int foo( void )
    {
        int x = 10;
    
        /* note, we've now reached the end of the function,
            and we aren't returning anything like we should. */
    }
    Quzah.
    Hope is the first step on the road to disappointment.

  4. #4
    Registered User
    Join Date
    Dec 2004
    Posts
    163
    thanks guys!

    I went to the gcc website, have a look, don't understand what it is talking about.

    I had tried both 02 and 03 and my program run faster when I used 02. But does 03 should run faster, since it is suppose to optimize further?

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    > But does 03 should run faster, since it is suppose to optimize further?
    Maybe.
    There are way too many factors to take into account for each increment in optimisation level to always produce a gain. -O3 is better than -O2 on some programs (an average set IIRC), but not all programs.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  6. #6
    Registered User
    Join Date
    Dec 2004
    Posts
    163
    ok, thanks for the help again!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  2. Replies: 10
    Last Post: 07-10-2008, 03:45 PM
  3. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  4. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 01:03 PM
  5. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM