| Newsgroups: |  comp.compilers | 
| Path: |  icdoc!ibmassc!yktnews!admin!newsgate.watson.ibm.com!uunet!decwrl!world!iecc!compilers-sender | 
| From: |  Diomidis Spinellis <dds@doc.imperial.ac.uk> | 
| Subject: |  Re: A lesson for compiler warning writers | 
| Message-ID: |  <92-06-091@comp.compilers> | 
| Keywords: |  C, lint | 
| Sender: |  compilers-sender@iecc.cambridge.ma.us | 
| Reply-To: |  Diomidis Spinellis <dds@doc.imperial.ac.uk> | 
| Organization: |  Compilers Central | 
| Date: |  Fri, 19 Jun 1992 14:49:47 GMT | 
| Approved: |  compilers@iecc.cambridge.ma.us | 
| Lines: |  30 | 
| Content-Length: |  1517 | 
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]
-- 
Send compilers articles to compilers@iecc.cambridge.ma.us or
{ima | spdcc | world}!iecc!compilers.  Meta-mail to compilers-request.
Newsgroup comp.compilers contents 
Newsgroup list 
Diomidis Spinellis home page
 
Unless otherwise expressly stated, all original material on this page created by Diomidis Spinellis is licensed under a Creative Commons Attribution-Share Alike 3.0 Greece License.