Path: utzoo!utgpu!water!watmath!clyde!bellcore!faline!ulysses!allegra!princeton!udel!gatech!hao!noao!mcdsun!sunburn!gtx!al From: al@gtx.UUCP Newsgroups: comp.lang.c Subject: functions defaulting to int Message-ID: <528@gtx.com> Date: 15 Jan 88 21:59:10 GMT Reply-To: al@gtx.UUCP (Al Filipski) Organization: GTX Corporation, Phoenix Lines: 41 Posted: Fri Jan 15 16:59:10 1988 To illustrate a point about C, I had occasion to write the following toy program: #include main() { int (*x)(); x = printf; (*x)("Hello, world\n"); } and was slightly irritated when cc (one on SV, one on BSD4.2) choked, saying "line 5: printf undefined". Neither the stdio.h on my AT&T 7300, nor the one on the SUN has int printf(); in it. This is one reason (maybe not an earth-shaking one, though) why the standard header files SHOULD contain declarations even for int procedures. I expect more will when ANSI C compilers come along because of the additional information in the prototypes. (Are declarations for library functions required by the standard? where will the system call declarations go?) mount /dev/soapbox . In my opinion, one of the main design flaws in C is the rule that makes procedures int by default. We had some vax code that called malloc() but didn't include malloc.h. Works fine on the vax, but on the M68000, malloc puts its return value (an address) in a0, then the calling program picks up the "int" it expects from d0, and the fun begins. Lint really pays for itself on occasions like this. umount /dev/soapbox ---------------------------------------------------------------------- | Alan Filipski, GTX Corp, 2501 W. Dunlap, Phoenix, Arizona 85021, USA | | {ihnp4,cbosgd,decvax,hplabs,seismo}!sun!sunburn!gtx!al (602)870-1696 | ---------------------------------------------------------------------- I wanted to put the quotation from Shakespeare about the "sea change" here, substituting "C" for "sea", but couldn't remember how it goes. Since looking something up would violate some Usenet rule, just pretend it's here.