What does "warning: control reaches end of non-void function imply?

I keep getting this warning from CodeBlocks:

warning: control reaches end of non-void function


I was just wondering...is the warning implying that non-void functions should never reach the end of a code block? If so can someone please explain why. I just do not want to get into a bad habit. Thanks

Here's the function CodeBlocks refers to:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
int ClassHandleEvents::HandleEvents()
{
    ///ACTIONS FOR CLICKING -DOWN- THE MOUSE BUTTON
        if(event.type == SDL_MOUSEBUTTONDOWN && event.button.button == SDL_BUTTON_LEFT)
        {
            if(introAndTitleScreen == true)
                return 1;
        }

    ///ACTIONS FOR CLICKING -UP- THE MOUSE BUTTON
        else if(event.type == SDL_MOUSEBUTTONUP)
        {
            ///put animation here
        }

        else if(event.type == SDL_MOUSEMOTION)
        {
            x = event.motion.x;
            y = event.motion.y;
        }
}
It means that you've got a function claiming to return something (an int) that (sometimes) doesn't return anything. It's bad.
Last edited on
is the warning implying that non-void functions should never reach the end of a code block?

Yes

If so can someone please explain why

Because doing so, for any function besides main(), invokes undefined behavior (ยง6.6.3/2 of the standard). As with any case of undefined behavior, the compiled program is allowed to do anything whatsoever.
Alright much thanks
Topic archived. No new replies allowed.