简体   繁体   中英

implicit declaration of function ‘getChar’ in C

Some I have this error when I try to compile a program in C.

myfunctions.c:27:2: warning: implicit declaration of function ‘getChar’ [-Wimplicit-function-declaration]

Here is line 27:

while(myChar = getChar() && myChar != '')

I'm calling this in the header:

#include <stdio.h>
#include <unistd.h>

It's spelled getchar , not getChar . C is case sensitive, and pretty much all the standard C functions' names are all lowercase.

As for why it's "implicitly declared" when it doesn't exist...in older versions of C, if a function name isn't known to the compiler, it's assumed to be a function that returns an int . It's almost as if you said int getChar(); . I hear C99 doesn't allow this, but most compilers don't stick to it anyway unless you tell them to.

I don't know why, but GCC compiler (win platform) knows getch() . But if you switch on -pedantic compilation, than this warning occurs.

Solution: use getchar() and everything should work ok.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM