missing return statement on non void functions; just a warning?

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

    missing return statement on non void functions; just a warning?

    I'm wondering what was the rationale that caused gcc to only have a
    warning (disabled by default!!) to signal the following:

    int a()
    {}; // intentionally no statements

    int main()
    {
    printf("%d", a());
    return 0;
    }

    Function a() is declared as returning an int and the compiler doesn't
    treat as an error the missing return statement.
    I'm asking in this forum because I suspect that gcc crowd will just
    tell me to read the standard. If I'm in the wrong forum, I hope to be
    corrected.

    Thank you,
    Adrian
  • Ian Collins

    #2
    Re: missing return statement on non void functions; just a warning?

    macracan wrote:
    I'm wondering what was the rationale that caused gcc to only have a
    warning (disabled by default!!) to signal the following:
    >
    int a()
    {}; // intentionally no statements
    >
    int main()
    {
    printf("%d", a());
    return 0;
    }
    >
    Function a() is declared as returning an int and the compiler doesn't
    treat as an error the missing return statement.
    I'm asking in this forum because I suspect that gcc crowd will just
    tell me to read the standard. If I'm in the wrong forum, I hope to be
    corrected.
    >
    You must have compiled it as C, it certainly won't compile as C++.

    --
    Ian Collins.

    Comment

    Working...