🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c.moderated
Article #2555

Re: compatibility

#2555
From: Kazimir Kylheku
Date: Tue, 09 Apr 1996 03:35
61 lines
2985 bytes
In article <4kbebh$eid@solutions.solon.com>,
Chris Torek  <torek@bsdi.com> wrote:

>C uses `name equivalence', but C also has separate compilation,

Not quite. C uses name equivalence for struct and union components of type
expressions.

>and does not require that type-names persist outside a compilation
>unit (`source file' after #include processing).  This leads to an
>obvious problem: there are no names with which to demand equivalency.
>Enter 6.1.2.6: since there are no names, the C standard calls for
>structural equivalence.
>
>The result is that TA and TB are compatible only in separate
>compilation units.  Within a single unit, they are incompatible.
>Any C compiler that fails to emit a diagnostic for the original
>sample program (not shown here) is not conformant.

Neat huh?

>Note that C's definition of a `type name' is a little unusual.  In
>most languages that use name equivalence, the language's `typedef'
>construct (however it is spelled) makes a new name, and hence a new
>type.  (I understand Ada lets you choose whether it is a new type or

A new typedef name does not introduce a new type. A new structure or union
_tag_ makes a unique structure or union type. Otherwise, structure equivalence
applies.

>a new name for an old type.)

One object declared to be of type (char (*)[10]) is perfectly compatible with
another object of type (char (*)[10]) based on the equivalence of the
constructed types. If I make two typedef names for the same type constructing
expression, they are compatible (unless one expression uses a structure or
union with a different tag).

	struct foo { int x; int y; };
	struct bar { int x; int y; };

	typedef struct foo TA;	/* TA and TB are compatible		*/
	typedef struct foo TB;

	typedef struct bar TC;	/* TC is not compatible with TA or TB	*/


I could extend the type constructions for TA and TB to arbitrary complexity,
and they would still retain compatibility---due to the structure equivalence of
types:

	typedef struct foo (* (*TA)())[3];
	typedef struct foo (* (*TB)())[3];
	typedef struct bar (* (*TC)())[3];


It still holds that TA and TB are equivalent, and TC is not compatible with
either, but now this fact can no longer be attributed to structure tag name
equivalence alone, but to the structural equivalence of the complex type
expressions _together_ with structure tag name equivalence.
-- 
Technical Details
Message-ID: <4kclti$ong@solutions.solon.com>
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail
References: <4jtt2c$3eq@solutions.solon.com> <4k1qi3$5ig@solutions.solon.com> <4k5vop$9ub@solutions.solon.com> <4kbebh$eid@solutions.solon.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail
From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
Newsgroups: comp.lang.c.moderated
Subject: Re: compatibility
Date: 8 Apr 1996 22:35:14 -0500
Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
Sender: clc@solutions.solon.com
Approved: clc@solutions.solon.com
Message-ID: <4kclti$ong@solutions.solon.com>
References: <4jtt2c$3eq@solutions.solon.com> <4k1qi3$5ig@solutions.solon.com> <4k5vop$9ub@solutions.solon.com> <4kbebh$eid@solutions.solon.com>
NNTP-Posting-Host: solutions.solon.com