Newsgroups: | comp.compilers |
From: | Diomidis Spinellis <dds@doc.imperial.ac.uk> |
Keywords: | C, lint |
Organization: | Compilers Central |
Date: | Fri, 19 Jun 1992 14:49:47 GMT |
arnold@cc.gatech.edu (Arnold Robbins) writes:
> file a.c:
> double foo(long a) { return a * 2.0 ; }
> file b.c
> extern short foo(double a);
[...]
> Both files will compile just fine. [...] But when you link the two
> objects together, the output will be either garbage or a core dump.
> lint will catch this, the C compiler won't.
There are methods to catch this at link time, with existing linker
technology.. See pp. 122-127 Margaret A. Ellis and Bjarne Stroustrup,
The Annotated C++ Reference Manual, Addison-Wesley, 1990 and Diomidis
Spinellis, Type-safe Linkage for Variables and Functions SIGPLAN
Notices 26(8):74-79, August 1991.
Diomidis
--
Diomidis Spinellis Internet: <dds@doc.ic.ac.uk> UUCP: ...!ukc!icdoc!dds
Department of Computing, Imperial College, London SW7
[Good point. In about 1975, when Dartmouth College wrote their first linker
to go with the PL/I compiler (the other compilers were so fast that it wasn't
worth saving object code, much less linking) and they had a type matching
hack: The compiler annotated each external definition and reference with
a string of type data, and the linker complained if the type strings weren't
the same. Simple, fast, and effective. I presume the C++ approach is
similar, albeit with the type info encoded in the symbol name. -John]
--
Return to the
comp.compilers page.
Search the
comp.compilers archives again.