Mail Archives: djgpp/2000/07/07/08:05:50
J-P <jstacey AT plato DOT wadham DOT ox DOT ac DOT uk> wrote:
> Does anyone know why this program works "as-is" i.e. with no extra
> pre-compiler #include lines:
It works for no better reason than luck, combined with some laziness
of the makers of the C programming language, back in 1979.
C allows you to call functions defined elsewhere even if you give it
no information at all about their argument and return types, as is
usually found in the relevant #include. In such cases, it'll assume
that the function's return value is int, and all numeric arguments, if
any, are int or double. You may be glad to hear that part of this has
been disallowed by the recent new C language standard, C99.
You're lucky because getch() happens to fit this description
reasonably well to allow the program to work, even the compiler
doesn't know about the details of that function.
gcc accepts this, but if you compile with a recommended selection of
compiler flags like '-g -O2 -Wall', it'll warn you about it, telling
you that there is an 'implicit declaration of function getch()' in
line 3 of your code.
Remember: compiler warnings are your friend --- enable them!
--
Hans-Bernhard Broeker (broeker AT physik DOT rwth-aachen DOT de)
Even if all the snow were burnt, ashes would remain.
- Raw text -