Intel® C++ Compiler
Support and discussions for creating C++ code that runs on platforms based on Intel® processors.
Announcements
Welcome to the Intel Community. If you get an answer you like, please mark it as an Accepted Solution to help others. Thank you!
7568 Discussions

implicit declaration warning not produced using C compiler

Jay_S_
Beginner
500 Views

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;
}

 

0 Kudos
2 Replies
Melanie_B_Intel
Employee
500 Views

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

 

Kittur_G_Intel
Employee
500 Views

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

Reply