Jacob, if you're going to post a followup on the newsgroup, please
don't send it to me by e-mail as well. If you must send me a copy by
e-mail, please say so in the message so I don't waste my time replying
twice. (I saw your e-mail before the same message showed up the
newsgroup.)
For the benefit of others, here's my reply again.
]
The thread was about a user complaining that this warning
was contradicting the standard. I get flamed anyway
Depending on how the warning is phrased, the user is probably wrong.
Nothing in the standard forbids issuing whatever warnings you like.
If you're going to be flamed anyway, you might as well do what you like.
How can I issue a warning about something that is
*explicitely* allowed?
Um, by issuing a warning about something that is explicitly allowed.
(Presumably a diagnostic about something that's not allowed would be an
error message, not a warning.)
I thought about that but it looks
weird isn't it? If the standard explicitely allows this
stuff a warning is misplaced. A better way would be
to change the standard, what looks like a minor change to
C99.
The change in C99 was deliberate. A lot of us agree that it was a bad
idea, but it wasn't an accidental bug. Now that it's in the standard,
changing it would break existing valid code, so that's just not going
to happen.
Most compilers distinguish between error messages (which cause the
compilation to fail) and warnings (which don't). Some provide more
levels of diagnostics, such as informational messages. Most compilers
that provide more than one level of diagnostic provide options to
disable the lower levels (disable warnings, or show warnings but disable
informational messages). Some, including gcc, provide some options that
disable certain specific warnings.
You should almost certainly issue a warning if control can reach the
end of a non-void function other than main(), even though this isn't
strictly an error. It causes undefined behavior only if the caller uses
the result, and there's no requirement to warn about undefined behavior,
but it's almost certainly something that the programmer should fix.
If you want to warn about reaching the end of main(), I suggest using
a different message, acknowledging that it's well-defined in C99 but
invalid in C90.
There are a number of things you can do. You can issue a warning message
for a program that falls off the end of main(). You can issue something
weaker than a warning, perhaps an informational or style message.
You can provide, or not provide, an option to disable the diagnostic,
either individually or in combination with other diagnostics. You can
allow the user to control the option by means of a formatted comment
in the source, similar to what lint does, or in a config file in the
user's home directory. If you provide such an option, you can either
enable or disable the diagnostic by default.
If you want to follow the spirit of C99, it's clear that falling off
the end of main() is intended by the standard to be perfectly valid;
this argues for disabling the diagnostic by default, but it's entirely
up to you.
The only things you *can't* do are:
1. In C99 mode, reject an otherwise correct program that falls off
the end of main() (issuing a diagnostic is permitted).
2. Claim that the C99 standard doesn't allow you to issue the diagnostic
(it clearly does).
You *can* worry as much as you like about being flamed for whichever
decision you make, but I don't recommend it.