0

Why is it when compiling source code with the Wall option enabled, that calling certain functions produces warnings such as warning: incompatible implicit declaration of built-in function 'strcpy' [enabled by default]|"

I looked up the function and added its header and the warning went away. What are the pros and cons of adding a header when (apparently) it's not needed?

Celeritas
  • 14,489
  • 36
  • 113
  • 194
  • 1
    You should consider upgrading to a C99 compiler. With GCC it is easy: just download the latest version and compile with `-std=c99`. – Lundin Sep 30 '13 at 14:09
  • possible duplicate of [warning: incompatible implicit declaration of built-in function ‘xyz’](http://stackoverflow.com/questions/977233/warning-incompatible-implicit-declaration-of-built-in-function-xyz). – Joshua Taylor Sep 30 '13 at 14:10
  • In addition to the one mentioned above, many of the results of [searching for this message on StackOverflow](http://stackoverflow.com/search?q=warning%3A+incompatible+implicit+declaration+of+built-in+function+is%3Aquestion) could also be considered duplicates. – Joshua Taylor Sep 30 '13 at 14:11
  • @Lundin I know this sounds stupid but I'm developing in a different machine than latter will be compiling. Since I didn't install GCC on the other machine I'm not sure which version it has. How do I check which version (for example C99) it is? – Celeritas Sep 30 '13 at 14:15
  • You don't necessarily need to update GCC. Just enable warnings and pay attention to them. – Keith Thompson Sep 30 '13 at 14:22

3 Answers3

8

There are no "pros and cons". You must always include the header before using functions declared therein. You should consider it an outright error to do otherwise. The fact that C allows "implicit declarations" is a historic relic that should never, ever be used in actual code.

Kerrek SB
  • 464,522
  • 92
  • 875
  • 1,084
3

When you forgot to include the header, The compiler assumes that the function has a return type of int, this is called implicit declaration. The advice would be don't use it, as it's error-prone and it's removed since C99.

Yu Hao
  • 119,891
  • 44
  • 235
  • 294
0

Because all strcpy,strcat are built in function .It directly look up the file string.h

neela
  • 1
  • 1