Prototypes

Steve Resnick stever at Octopus.COM
Tue Jul 10 10:39:12 AEST 1990


In article <559 at csource.oz.au> david at csource.oz.au (david nugent) writes:
>In <55550 at lanl.gov> rdw2030 at 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 -<stever at octopus.COM apple!octopus!stever sun!vsi1!octopus!stever>
408/241-1533 Process Scientific, Inc.
"0x2B|~0x2B THAT is the question!"



More information about the Comp.lang.c mailing list