Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!sdd.hp.com!decwrl!nsc!pyramid!octopus!stever From: stever@Octopus.COM (Steve Resnick ) Newsgroups: comp.lang.c Subject: Re: Prototypes Message-ID: <1990Jul10.003912.20412@Octopus.COM> Date: 10 Jul 90 00:39:12 GMT References: <55550@lanl.gov> <559@csource.oz.au> Reply-To: stever@octopus.UUCP (Steve Resnick ) Organization: Octopus Enterprises, Cupertino CA Lines: 37 In article <559@csource.oz.au> david@csource.oz.au (david nugent) writes: >In <55550@lanl.gov> rdw2030@venus.tamu.edu writes: > >>With all this talk about prototypes lately, I must admit... though I've been >>programming in C for years, I've never understood why they exist! Programs >>run without them! > >>what is their purpose!? > [I know this is referenced wrong but I missed the original] There are a few "ansi" compilers around which are "broken" without prototypes. In Turbo C, for instance, calling malloc without the prototype doesn't work in large memory model (eg returns a 32bit pointer) becuase it (correctly) assumes that the function returns an int. (I found this out by getting my pointer value returned with the upper 16 bits set to zero and pointing into the interrupt vector table on my PC - real nice "feature" (-8). Turbo C has also made assumptions about function arguments being ints as well. I have also encountered this on Microsoft C. The bottom line is that when you provide your compiler with a prototype, the compiler shouldn't make any assumptions about what's being passed or returned and you get much better error checking. (Even though it's a pain in the arse to get used to doing at first!) There are a few compilers which will generate the prototypes for you, too! (Microsoft for instance) Adding my $.02 to the pot, now deal the cards! :) Steve -- -------------------------------------------------------------------------------- Steve Resnick - 408/241-1533 Process Scientific, Inc. "0x2B|~0x2B THAT is the question!"