Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!apple!bionet!agate!ucbvax!hplabs!hpfcso!hppad!bazza From: bazza@hppad.HP.COM (Carlos Bazzarella) Newsgroups: comp.lang.c Subject: Re: ttyname() - question Message-ID: <1860001@hppad.HP.COM> Date: 30 Aug 89 13:03:15 GMT References: <99@lkbpyr.UUCP> Organization: HP Panacom Automation Div Waterloo, Ont. Lines: 54 Hello, I was wondering why this work: -------------------------------------- #include main() { char *term; char *ttyname(); term=ttyname(); printf("%d",term); } --------------------------------------- And why this don't: -------------------------------------- #include main() { test(); } test() { char *term; char *ttyname(); term=ttyname(); printf("%d",term); } ---------------------------------------- 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. there are 2 things you can do. first you could move the test() function prior to main(), that way by the time main() is compiled, test() will the ready. second you could declared test() on top of your program or in a include file, so when main() is compiled, test() will be given a function overhead, that way the linker will know what to do with test(). a function declaration, for your case, looks like this: void test(); 3 1 2 /* it reads: test (1) is a function (2) with no * returning value (void (2)) */ Carlos Bazzarella. University of Waterloo.