From: Hans-Bernhard Broeker Newsgroups: comp.os.msdos.djgpp Subject: Re: getch() mysteriously defined Date: 7 Jul 2000 10:22:14 GMT Organization: Aachen University of Technology (RWTH) Lines: 27 Message-ID: <8k4b0m$elr$1@nets3.rz.RWTH-Aachen.DE> References: <8k470e$262$1 AT plato DOT wadham DOT ox DOT ac DOT uk> NNTP-Posting-Host: acp3bf.physik.rwth-aachen.de X-Trace: nets3.rz.RWTH-Aachen.DE 962965334 15035 137.226.32.75 (7 Jul 2000 10:22:14 GMT) X-Complaints-To: abuse AT rwth-aachen DOT de NNTP-Posting-Date: 7 Jul 2000 10:22:14 GMT Originator: broeker@ To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com J-P 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.