Xref: utzoo comp.lang.c:33671 alt.religion.computers:2037 Path: utzoo!utgpu!cs.utexas.edu!usc!zaphod.mps.ohio-state.edu!mips!apple!netcom!teda!ditka!mcdchg!tellab5!balr!clrcom!rmartin From: rmartin@clear.com (Bob Martin) Newsgroups: comp.lang.c,alt.religion.computers Subject: Re: ANSI C prototypes Message-ID: <1990Nov6.002848.3634@clear.com> Date: 6 Nov 90 00:28:48 GMT References: <1005@christopher-robin.cs.bham.ac.uk> <1906@necisa.ho.necisa.oz> Organization: Clear Communications, Inc. Lines: 48 In article <1906@necisa.ho.necisa.oz> boyd@necisa.ho.necisa.oz (Boyd Roberts) writes: > > Right on! The function prototypes are just stupid. I shouldn't have to go: > > extern gore *good(const char *vomit); > > to get the functionality of type checking of function arguments. > The compiler and loader should do it. > The C++ compiler does this. If you declare a function one way and use it in another, say with different type arguments, then the program won't link. C++ does this by mangling the return type and argument types into the function name. Thus when you declare a function: int x(int y) the compiler generates a new name for the function which is what the loader sees. This name would specify that the function's name was x, that it returned an int and that it had a single int parameter. So if you screw up your declarations, or attempt to use implicit declarations (bad style), you cannot get a runtime error becuase of a type mismatch. The linker will catch the problem. -- By the way, this technique of mangling the function names means that int x(int y); and double x(double y); are completely different functions. You can declare both of them, define them separately and call the proper function by making sure that the types are correct. +----------------------+---------------------------------------------+ | Robert C. Martin | The authors opinions are his own and do not | | rmartin@clear.com | represent the opinions of his employer. | | uunet!clrcom!rmartin | | +----------------------+---------------------------------------------+ -- +----------------------+---------------------------------------------+ | Robert C. Martin | The authors opinions are his own and do not | | rmartin@clear.com | represent the opinions of his employer. |