ttyname() - question

Conor P. Cahill cpcahil at virtech.UUCP
Fri Sep 1 10:22:45 AEST 1989


In article <1860001 at hppad.HP.COM>, bazza at 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     |
+-----------------------------------------------------------------------+



More information about the Comp.lang.c mailing list