Compiling the below code in gcc (gcc -Wall foo.c) yields the following warning message:
foo.c: In function 'main':
foo.c:9: warning: implicit declaration of function 'strlen'
foo.c:9: warning: incompatible implicit declaration of built-in function 'strlen'
When I compile using Intel C++ compiler (icpc -Wall foo.c) I get the below error message:
foo.c(9): error: identifier "strlen" is undefined
len = strlen(foo);
When I compile using Intel C compiler (icc -Wall foo.c) no warning messages are displayed. Why is this the case?
#include <stdlib.h>
int main (int argc, char **argv)
{
char foo[] = "abcd";
int len;
len = strlen(foo);
return 0;
}
We don't have the exact same warnings as gcc, though we try.
If you want to see the message about strlen's declaration when using icc, use this option: -ww:266
icc -c -ww:266 fu.c
fu.c(24): warning #266: function "strlen" declared implicitly
len = strlen(foo);
If you use either g++ or icpc to compile it, the fact that strlen isn't declared is emitted as an error, no implicit declaration for strlen in C++.
--Melanie
Thanks Melanie for the response on warning compatibility with ICC. Just to elaborate further, ICC is command line, source and binary compatible. Although not warning to warning compatible with GCC, ICC often produces a high number of warnings (instead of silently accepting) thereby detecting source oddities that can end up as a potential bug. The user can then decide on whether the warning is an issue or not and disable accordingly.
_Kittur
For more complete information about compiler optimizations, see our Optimization Notice.