|
|
Richard Heathfield <rjh@xxxxxxxxxxxxxxx> writes:
> Keith Thompson said:
[...]
>> But you (that's a generic "you") shouldn't assume that the compiler
>> either will or will not warn you about incorrect calls. It's up to
>> the programmer to get this right in the first place.
>
> Well, you're right - I'm forever forgetting to #include <string.h>, and
> being bluntly reminded of the fact only when I compile the code on a Win32
> box, because my Linux-based compiler simply isn't interested, no matter
> how many diagnostic switches I set, so I ought to know by now that I can't
> rely on the compiler to diagnose me out of trouble - but it's a
> non-trivial problem (in the general case); it's easy to forget to add a
> header, and saying "Don't Do That" doesn't really help much.
<OT>
Perhaps it's time for an upgrade. Consider the following program,
which I presume is the kind of thing you're talking about (note the
missing "#include <string.h>"):
#include <stdio.h>
int main(void)
{
char *s = "hello";
size_t len = strlen(s);
printf("len = %d\n", (int)len);
return 0;
}
With gcc 3.4.4, "-Wall" triggers "warning: implicit declaration of
function `strlen'".
With gcc 4.1.3, even with no options I get "warning: incompatible
implicit declaration of built-in function 'strlen'".
</OT>
--
Keith Thompson (The_Other_Keith) <kst-u@xxxxxxx>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
|
|