|
From: Per W. <pw...@ia...> - 2002-11-05 23:02:02
|
There is one thing what you MAY do, and another what you SHOULD do.
You need to #include <string.h> to let the compiler know exactly which
parameters the strcmp function takes and what return value.
If you don't the compiler will assume that it returns int (correct in this
case) and you may send in any parameters. The compiler would in this case
have allowed you to send in integers or floating point values too, but
when you run the program, it would immediately fail, since strcmp assumed
that it received two string pointers.
When compiling C programs, you should NEVER call a function wihout the
correct #include, or by specifying a function prototype yourself, in case
it is a function written by you.
The parameter -Wimplicit-function-declaration (or -Wall) will tell the
compiler to always warn when you call a function which hasn't been already
declared. If you split your code into multiple modules, you may also use
-Wmissing-prototypes to verify that every global function has a function
declaration.
/Per W
On Tue, 5 Nov 2002, Santiago wrote:
> Hi all,
> In the two books I have, it says that in order to use the C-Style function strcmp, I need to #include <string.h>. I tried the following in compilers including DevC++ and it works.......?
> //no includes.....
> int main()
> {
> char a[] = "Hello";
> int i = strcmp(a, "There");
> return 0;
> }
>
> To better show you, I didn't use any #include. Anyone has any idea as to why this program compiles? If iostream.h is added and if you cout<<i then it shows the returned value.
>
> Thanks for your feedback.
>
> San
>
|