ANSI C prototypes
Bob Martin
rmartin at clear.com
Tue Nov 6 11:28:48 AEST 1990
In article <1906 at necisa.ho.necisa.oz>
boyd at 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 at clear.com | represent the opinions of his employer. |
| uunet!clrcom!rmartin | |
+----------------------+---------------------------------------------+
--
+----------------------+---------------------------------------------+
| Robert C. Martin | The authors opinions are his own and do not |
| rmartin at clear.com | represent the opinions of his employer. |
More information about the Comp.lang.c
mailing list