I'm using Visual studio for my code development and when I used the function
getche()
The compiler gave me this warning
warning C4013: 'getche' undefined; assuming extern returning int
But the getche() function is working just as expected , why compiler is showing such a warning , and How can I eliminate this warning?
As your compiler is telling you, getche
has not been defined.
Usually, you would include a header (e.g. #include <conio.h>
) that will define the function somewhat similar to:
int getche(void);
There is a rule for the C language that allows usage of functions which have not been defined before. These functions are assumed to take the exact argument types they are passed (none, so void
) and return int
. Due to this feature (which is evil™) and the fact that getche
does indeed get linked in due to your linker settings, your program actually works correctly.
Be aware that getche
is deprecated and you should use _getche
instead.