Joachim Schmitz said:
Peter J. Holzer said:
//c-faq.com/malloc/mallocnocast.html[/url]
Thanx. Though I don't buy in that "argument". [...]
At least lcc-win32 DOES warn you: "Missing prototype for 'malloc'.
Same with Pelles C: "Missing prototype for 'malloc'".
Same with gcc: "implicit declaration of function 'malloc'".
Once upon a time most compilers didn't warn about missing prototypes but
they did warn about conversions from int to a pointer. In these days not
casting malloc was the most reliable way to catch a missing declaration
of malloc.
Because they are required to do diagnose the conversionm and free to do do
the same with the missing prototype
oops, spelling/typing problems, sorry...
Because they are required to diagnose the conversion and free to diagnose
the missing prototype
Actually, most of the compilers I was thinking about were pre-ANSI, so
they weren't required to do anything. It's probably the other way
around: Because most compilers already warned about int<->pointer
conversions the ANSI committee made that warning mandatory and because
most compilers did not warn about implicitely declared functions and a
lot of existing code relied on that they had to allow that.
As an aside, GCC still isn't able to warn about a missing prototype.
Today this isn't much of a problem since old-style declarations have
gone out of fashion, but when system header files still contained lots
of them, there was no sane combination of warning flags:
* -Wimplicit only warned if there was no declaration of malloc at
all. If the declaration was "void *malloc()", it wouldn't warn
about "p = malloc(10)", even though int and size_t might be of
different sizes.
* -Wstrict-prototypes was unusable: It would produce hundreds of
warnings for the system header files.
* -Wmissing-prototypes does something completely different.
Back to the topic: The standard doesn't require any specific form of a
diagnostic. A compiler which always prints "Warning: This program may
contain constraint violations" would be conforming, but of appallingly
bad quality. So for this discussion, I think it is completely irrelevant
whether something is a constraint violation or not. What is relevant is
whether real, existing, and widely used compilers issue useful warnings.
hp