Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!wuarchive!wugate!uunet!virtech!cpcahil From: cpcahil@virtech.UUCP (Conor P. Cahill) Newsgroups: comp.lang.c Subject: Re: ttyname() - question Message-ID: <1106@virtech.UUCP> Date: 1 Sep 89 00:22:45 GMT References: <99@lkbpyr.UUCP> <1860001@hppad.HP.COM> Organization: Virtual Technologies Inc Lines: 25 In article <1860001@hppad.HP.COM>, bazza@hppad.HP.COM (Carlos Bazzarella) writes: > The second one doesn't work because when the > compiler gets to main() and sees test(), he doesn't > know what to do with it, since it was not > previously defined or compiled. I think you need to go back and read your C book again. There is no requirement that functions be defined before being used in C. If there was, every program that uses standard library calls (which the compiler usually knows nothing about) would blow up. The only requirement for pre-definition is that the function is assumed to return an int if it is used before any declaration/definition. In this example the function does return an int so no problem. As I said in an earlier message the problem with the code is that the ttyname() function requires a file descriptor argument. (Several others also pointed out the typo in the printf("%d", but since the author said the first sample worked I would assume that the %d was a typo added when he typed the article. -- +-----------------------------------------------------------------------+ | Conor P. Cahill uunet!virtech!cpcahil 703-430-9247 ! | Virtual Technologies Inc., P. O. Box 876, Sterling, VA 22170 | +-----------------------------------------------------------------------+