Article View: comp.lang.c.moderated
Article #2536Re: Newsgroups: comp.lang.c,comp.lang.c++,comp.lang.c++.moderated,comp.lang.c.moderated
From: Lawrence Kirby
Date: Sat, 06 Apr 1996 14:52
Date: Sat, 06 Apr 1996 14:52
48 lines
2313 bytes
2313 bytes
In article <4k1q2a$59u@solutions.solon.com> rdwells@mmm.com writes:
>USENET News System wrote:
>>
>> /* Under the Microsoft Visual C++ 2.0 and 4.0 the following
>> was observed. */
>>
>> typedef struct { int a; int b; } *TA;
>> typedef struct { int a; int b; } *TB;
>>
>> void
>> f( TA x, TB y )
>> {
>> f ( y, x); /* This compiles fine */
>> }
>
>I think VC++ has this right. Section 6.1.2.6 of the standard says:
>
> Moreover, two structure, union, or enumeration types declared
> in separate translation units are compatible if they have the
> same number of members, the same member names, and compatible
> member types; for two structures, the members shall be in the
> same order...
>
>Of course, this mentions "separate translation units", which
>doesn't apply in this case, so perhaps my reading is incorrect.
Correct, it doesn't apply in this case. That statement in the standard allows
you to write:
extern struct { int a; int b} A;
in 2 translation units. For that to be well defined the type of A in each
translation unit must be compatible.
However in the original case TA and TB are in the same translation unit
and do not have compatible type.
'Compatible' doesn't really correspond to anything very tangible. You just
have to follow the rules to determine whether 2 types are compatible.
'Compatibility' is then used by other parts of the standard to define
whether particular constructs are legal or not.
--
-----------------------------------------
Lawrence Kirby | fred@genesis.demon.co.uk
Wilts, England | 70734.126@compuserve.com
-----------------------------------------
Technical Details
Message-ID:
<4k60eo$ad7@solutions.solon.com>Path:
arc1-ca.pugleaf.net!solon.com!not-for-mailReferences:
<4jtt2c$3eq@solutions.solon.com> <4k1q2a$59u@solutions.solon.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail From: Lawrence Kirby <fred@genesis.demon.co.uk> Newsgroups: comp.lang.c.moderated Subject: Re: Newsgroups: comp.lang.c,comp.lang.c++,comp.lang.c++.moderated,comp.lang.c.moderated Date: 6 Apr 1996 08:52:08 -0600 Organization: none Sender: clc@solutions.solon.com Approved: clc@solutions.solon.com Message-ID: <4k60eo$ad7@solutions.solon.com> References: <4jtt2c$3eq@solutions.solon.com> <4k1q2a$59u@solutions.solon.com> Reply-To: fred@genesis.demon.co.uk NNTP-Posting-Host: solutions.solon.com X-Newsreader: Demon Internet Simple News v1.27 X-Mail2News-Path: genesis.demon.co.uk