Path: csiph.com!eternal-september.org!feeder.eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: Tim Rentsch
Newsgroups: comp.lang.c++
Subject: Re: Union type punning in C++
Date: Tue, 14 Jan 2020 07:30:35 -0800
Organization: A noiseless patient Spider
Lines: 36
Message-ID: <86a76qgin8.fsf@linuxsc.com>
References: <490dd5d6-fb8a-482b-a88d-550b8a4defd0@googlegroups.com> <86d0bq2fmi.fsf@linuxsc.com> <140b2e3a-cc88-45f9-a292-efd471e3c789@googlegroups.com> <86r203guiq.fsf@linuxsc.com> <2e087cbf-8a15-4109-b199-f200487745f6@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: reader02.eternal-september.org; posting-host="2dd0ff26386f9ade01e1210d85a64307"; logging-data="25738"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18NNpXNSDlJGys5Mwu1bzupNQUHeD1+4Z8="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:Vj23G/2IzOhfaZtGtLCLNPRBqxE= sha1:ugAnJgXThmc58aLOK8wwjAG3krg=
Xref: csiph.com comp.lang.c++:71341
Tiib writes:
> On Monday, 13 January 2020 19:02:00 UTC+2, Tim Rentsch wrote:
[context: this code
struct base {
int p0;
};
struct object_0 {
base b;
int p0;
};
]
>> The first member of struct base is of type 'int'. The first member of
>> struct object_0 is of type 'base'. The two types, 'int' and 'base',
>> are not layout compatible. Do you agree or disagree?
>
> I disagree. The address of base is required to be address of int as
> well as first element of base so these are layout compatible.
In N4659, section 6.9 paragraph 11 defines the term 'layout
compatible'. The definition says (leaving out the cv's) that two
types T1 and T2 are layout compatible if
(a) T1 and T2 are the same type,
(b) T1 and T2 are layout-compatible enumerations, or
(c) T1 and T2 are layout-compatible standard-layout class types.
When T1 is 'int' and T2 is 'base' (aka 'struct base'), which of these
categories do you think applies?