Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!rutgers!njin!princeton!jonlab!jon From: jon@jonlab.UUCP (Jon H. LaBadie) Newsgroups: comp.lang.c Subject: Re: (* func)(fred, bert) Summary: Not certain this adds much, but I encountered a problem by "lying" about main's return type Message-ID: <824@jonlab.UUCP> Date: 27 Nov 89 05:07:47 GMT References: <2387@stl.stc.co.uk> <744@lakart.UUCP> <0175@sheol.UUCP> <0200@sheol.UUCP> Organization: 4455 Province Line Rd., Princeton, NJ 08540 Lines: 55 In article <0200@sheol.UUCP>, throopw@sheol.UUCP (Wayne Throop) writes: > > darcy@bbm.UUCP (D'Arcy Cain) > > I don't think it is "lying" to your compiler to > > [.. declare main an void ..]. > > I call declaring main an void "lying to your compiler" because in most > environments you are perforce (or at least perprobably) going to be > linking with a module that has declared it an int (eg: crt0 from many > implementation of the C startup code). > > > I should like to hear details of a case where the code will not > > work. It seems ridiculous to declare un-portable the results of a > > void-vs-int return linkage which is never made, and I should like > > to hear of an implementation where this actually fails. > > If no real-world example is available, I should be almost as > > satisfied with a conjectural example (clearly marked as conjecture). I encountered one instance where "declaring" main to be other than int caused severe problems. The file containg main was organized as follows: #include struct foo { various members; } /* 70 lines of comments - yes comments */ main() { ... } Note the missing semicolon, failing to terminate the declaration of struct foo, and thus serving to define main as a function returning a struct foo. The page+ of intervening comments were merely white space. The development environment, a MC68010 UniSoft implementation, had no problems. One of the target environments, either a VAX 780, or a Sritek co-processor for a PC/AT - I forget which, did have problems. It core dumped upon exiting. Imagine trying to explain to a client, the program you delivered runs fine, does everything it is supposed to, it just core dumps every time you use it. Perhaps this is a more severe situation than a void vs. int lie about main's return value. But the principle remains intact - if the calling and the called function are not in sync regarding their interface, then the potential for trouble exists. -- Jon LaBadie {att, princeton, bcr}!jonlab!jon {att, attmail, bcr}!auxnj!jon