Newsgroups: | comp.compilers |
From: | igor!voltaire!davidm@uunet.UU.NET (David Moore) |
Keywords: | lint, design, C++ |
Organization: | Compilers Central |
References: | <19920609091040SEB1525@MVS.draper.com> 92-06-084 |
Date: | Fri, 19 Jun 1992 16:37:28 GMT |
arnold@cc.gatech.edu (Arnold Robbins) writes:
[C doesn't catch type mismatches in separately compiled modules.]
In a language like C, which was never designed to promote consistency
across compilation units (unlike the Modula familly and Ada), a good
compiler can reduce this problem by generating link names with type
information appended to them. This idea dates back at least to the
mid-seventies, though at that time, the technique could not be used on
most machines because external names were limited to a small number of
characters by the linker.
In C++, you have to use this technique since procedures can be overloaded,
so the name does not uniquely define a procedure. An external linker will
require a unique identifer for each procedure.
As far as I can see, though, this technique limits you to using structural
equivalence for types. In languages like Ada, if I declare:
A:ARRAY(1..10) OF CHARACTER;
B:ARRAY(1..10) OF CHARACTER;
Then A and B have different types (because their types have different
(anonymous) names). With name equivalence, I would get a different type
for A in every compilation unit. The reliance on structural equivalence is
a significant difficulty in C++ (see, for example, Bjarne Stroustrup "The
C++ Programming Language" section 4.2 "Linkage" (page 110 in the second
edition)
--
Return to the
comp.compilers page.
Search the
comp.compilers archives again.