Topic: Type Equivalence (Clause 9.1)


Author: fwai@armltd.co.uk (Francis Wai)
Date: 1995/07/24
Raw View
dqua@earthlink.net (Derick J.R. Qua-Gonzalez) writes:

>While reading the Working Paper, clause 9.1, I was wondering what the
>rationale was behind the following.

>Why does the WP stipulate that:

>       struct S { int a; }
>       struct S { int a; }         // error -- multiply defined `S'

>is an error?

>Why the fuss? I can see the _name equivalence_
>checking is much faster; is this the reason?

Section 2.5 of The Design and Evolution of C++ gives the answer.
--
e-mail: fwai@armltd.co.uk





Author: dqua@earthlink.net (Derick J.R. Qua-Gonzalez)
Date: 1995/07/21
Raw View
While reading the Working Paper, clause 9.1, I was wondering what the
rationale was behind the following.

Why does the WP stipulate that:

       struct S { int a; }
       struct S { int a; }         // error -- multiply defined `S'

is an error? It does not seem to be a very difficult matter to create
a tag in the symbol table, akin to a mangled function name, that allows
the compiler to check for type equivalence at compile time. Since the
above decls are compatible, why is it deemed an error?

   Similarly,

       struct S1 { int a; }
       struct S2 { int z; }
       S1 anS1 = 3;
       S2 anS2;

       anS2 = anS2;       // error---assigning an S2 into an S1

is considered an error. I can see that they _are_ different type _names_,
but they are structurally equivalent; in fact, the space of the two types
S1 and S2 are identical. Why the fuss? I can see the _name equivalence_
checking is much faster; is this the reason? It is feasible that the com-
piler be able to create a type-compatibility graph (i.e., partition the
set of types into equivalence classes).

Thanks.

Best regards,
Derick.

--
+-----------------------------------------------------------------------------+
| Derick R. Qua-Gonzalez                                           | ________ |
| Department of High Energy Physics, California State University   | \      / |
| dqua@Prometheus.EarthLink.Net                                    |  \    /  |
|        ``It is better to be hated for what one is,               |   \  /   |
|          than loved for what one is not.'' (A. Gide)             | G  \/ USA|
+------------------------------------------------------------------+----------+
| mQBNAy/qJJMAAAECANBCB543eTUkdG8Mqx6K2cm3WxCVtKY8ZbB9WY6A2Ne4dQi8 | PGP2.6.2 |
| xh7OxjHXP/eXp5BSbmVAihEGd7r+5g/yknko56kABRG0MERKUiBRdWEtR29uemFs |  Public  |
| ZXogPGRxdWFAUHJvbWV0aGV1cy5FYXJ0aGxpbmsuTmV0Pg==                 | KeyBlock |
| =70DW                                                            | 06.20.95 |
+------------------------------------------------------------------+----------+