Path: utzoo!attcan!uunet!lll-winken!lll-lcc!ames!pasteur!ucbvax!decwrl!decvax!ima!cfisun!lakart!dg From: dg@lakart.UUCP (David Goodenough) Newsgroups: comp.lang.c Subject: Re: YALF (yet another lint foulup) Message-ID: <379@lakart.UUCP> Date: 3 Jan 89 16:39:39 GMT References: <9255@smoke.BRL.MIL> Organization: Lakart Corporation, Newton, MA Lines: 63 From article <9255@smoke.BRL.MIL>, by gwyn@smoke.BRL.MIL (Doug Gwyn ): > In article <14672@cisunx.UUCP> cmf@unix.cis.pittsburgh.edu (Carl M. Fongheiser) writes: >>In article <9228@smoke.BRL.MIL> gwyn@brl.arpa (Doug Gwyn (VLD/VMB) ) writes: >>>Function value type and whether a function returns are orthogonal. >>Really? I'm having a good deal of difficulty thinking of any reason why >>one would declare a function which never returns as anything other than >>void. > > Where did you get the word "never"? Probably from the same place I did for the example below > unsigned int Square(unsigned int n) > { extern void exit(int); > extern void /*also nonreturning*/ Fatal(char*); > if (n >= 0x80) > Fatal("overflow in Square"); > return n*n; > } > > This, not entirely implausible, function sometimes returns and > sometimes doesn't. But that has nothing to do with its type. True, but probably irrelevant. What Mr. Fongheiser is referring to is something like: void command() { extern void exit(); for (;;) { switch (getchar()) { case 'q': exit(); /* NOTREACHED */ case 'a': a_command(); break; /* etc. etc. */ } } /* NOTREACHED */ } command() can NEVER (repeat NEVER) return. Hence to give it (say) type int is not sensible, meaningful or anything. :-) :-) smiley mode on :-) :-) What is in fact needed is ANOTHER function type notreturning, as opposed to void, because in one way void implies return, it also however imples return without a corresponding return value. notreturning imples that a function is a one way thing. lint could be made a lot more sensible about exit() if such a thing existed, and if we could figure out how to tell it about for (;;) without breaks, we could do away with /* NOTREACHED */ -- dg@lakart.UUCP - David Goodenough +---+ | +-+-+ ....... !harvard!xait!lakart!dg +-+-+ | AKA: dg%lakart.uucp@xait.xerox.com +---+