220 30248 <db74f34b-b0ab-46cb-b94a-eeb96ef10c2d@isocpp.org> article
Path: news.gmane.org!.POSTED!not-for-mail
From: Myriachan <myriachan@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: P0298: A byte type definition: with undefined
 pointer arithmetic?
Date: Wed, 4 Jan 2017 12:27:16 -0800 (PST)
Lines: 202
Approved: news@gmane.org
Message-ID: <db74f34b-b0ab-46cb-b94a-eeb96ef10c2d@isocpp.org>
References: <e21a1901-1ed5-5795-6244-dd70c4d08adf@f2.dion.ne.jp>
 <CACGiwhER_fU=bVY0nob5Tap9s=APgmeFS6sx6HQfnoPEKJjDVg@mail.gmail.com>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_2699_1556132105.1483561636496"
X-Trace: blaine.gmane.org 1483561640 24993 195.159.176.226 (4 Jan 2017 20:27:20 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Wed, 4 Jan 2017 20:27:20 +0000 (UTC)
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBDKLT4PURQHRBJNVWXBQKGQEXISDYXA@isocpp.org Wed Jan 04 21:27:15 2017
Return-path: <std-proposals+bncBDKLT4PURQHRBJNVWXBQKGQEXISDYXA@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-pg0-f71.google.com ([74.125.83.71])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBDKLT4PURQHRBJNVWXBQKGQEXISDYXA@isocpp.org>)
	id 1cOs9R-0005Ts-Th
	for gclcip-std-proposals@m.gmane.org; Wed, 04 Jan 2017 21:27:14 +0100
Original-Received: by mail-pg0-f71.google.com with SMTP id n189sf1034241831pga.4
        for <gclcip-std-proposals@m.gmane.org>; Wed, 04 Jan 2017 12:27:18 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=date:from:to:message-id:in-reply-to:references:subject:mime-version
         :x-original-sender:reply-to:precedence:mailing-list:list-id
         :x-spam-checked-in-group:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=PRFUkq9us3dYPwrf6aj8ZRIiISRsKrtlzlSBI6dXCmg=;
        b=tI/KGEtr8BjolqBJd9WZ7FMMBRss90/5rfV8ezd62btX09KXolt8nC8Tuc31+L+7Ix
         9EpAGAqTVOP5mCJzZPLdK0x+y8g8A6zuAabE8/3nO7Xv6Vg77SUXrqacm5JjxHEwXPsh
         7W8C2gPw8uheYTYlKKEAfOLEBZ4fCcAhPL+gIKSz+qFdJnVn9W8FxkuWhs72Eayvv4qQ
         rwjKiNVQnRnCWxHwhMt7ml7WITOM2KTLaD20/4gUZjDvAl6OJKjNOY1XzwnycLgL9XZE
         9Jv4nlTy8fOife5k9IuATvSSb2XaRGA1Os2hyLcDgmpW55ZQb738avbxyCmoBggRTWf4
         Gj+A==
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=date:from:to:message-id:in-reply-to:references:subject:mime-version
         :x-original-sender:reply-to:precedence:mailing-list:list-id
         :x-spam-checked-in-group:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=PRFUkq9us3dYPwrf6aj8ZRIiISRsKrtlzlSBI6dXCmg=;
        b=h5+Wg5/SutJLMzyoGJdohhaVno7BcRjaA2rkLSh/y6JB5sLUbX4xpL1QjuUIQf+96h
         OKCqrD1DaywPzrs7Rtx7X0Del5GRKFiIomeVsXRHiA6R6sWMG65Q6B1K9defqnAoNGZ3
         bkD3BcnS/lodhzfZqkXVYaRo3i4yndJFyVnrLtjpvq5TQOne+tdigGbHQ+sSdxOXavhm
         QEes01OV7VlqOybvJ1HlHHSHifUoCjEkLdZaOSQg3Q0XdZSXXEWYWqC6YHqJnPlWSFD7
         gr1FDp6ZHKVoVZrxWK+m1Z3o88hPA+ZWi/JD4Uc4jYJcK+baUgxu4bDDSUa4dERO3SC+
         o3gQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:date:from:to:message-id:in-reply-to:references
         :subject:mime-version:x-original-sender:reply-to:precedence
         :mailing-list:list-id:x-spam-checked-in-group:list-post:list-help
         :list-archive:list-subscribe:list-unsubscribe;
        bh=PRFUkq9us3dYPwrf6aj8ZRIiISRsKrtlzlSBI6dXCmg=;
        b=Wn6j6UCcUWLeKoLnp3Ywm527TZ9iV1lqDdOdmY62Rpj1isWHQ+1h05CYS9Ce5qnb6o
         Y1HZFrEPSa2Sk98PbhL5Lnvu/dUBlHiGKfQeMLoTzva9Txp7SiKqciwy+Zp+P+JCNs1B
         T5GZLLQKhuiQDj92JoTy9/ERc9uBy1O88txb2WgR2nK8D1OY8ORqoWutEVeav0zhr1Qe
         OZ+vTkv1x8w3ocSm5UoJ5e78tzKEmekLNaYv0jczUs5vSagsVfm/zzpt97ooo3njlGzf
         HF4KUvIahCvH2GAL1PQj0J/VUoKm6RG4uV5aKzFpOl76a7nwIwCfftq4pfdOGNQKAuR7
         427A==
X-Gm-Message-State: AIkVDXJDSiKs0/Kc47Jfsrpa9znW5+szAs/5XIE9jfq75IlRIZYJ8VKARqS6jJz1z4pmEQ==
X-Received: by 10.99.9.1 with SMTP id 1mr39306200pgj.66.1483561637605;
        Wed, 04 Jan 2017 12:27:17 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.157.13.110 with SMTP id 101ls5275462oti.25.gmail; Wed, 04 Jan
 2017 12:27:16 -0800 (PST)
X-Received: by 10.157.8.134 with SMTP id 6mr3380525otf.17.1483561636962;
        Wed, 04 Jan 2017 12:27:16 -0800 (PST)
In-Reply-To: <CACGiwhER_fU=bVY0nob5Tap9s=APgmeFS6sx6HQfnoPEKJjDVg@mail.gmail.com>
X-Original-Sender: myriachan@gmail.com
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <std-proposals.isocpp.org>
X-Google-Group-Id: 399137483710
List-Post: <https://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <https://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <https://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <https://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>,
 <https://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:30248
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/30248>

------=_Part_2699_1556132105.1483561636496
Content-Type: multipart/alternative; 
	boundary="----=_Part_2700_971713874.1483561636496"

------=_Part_2700_971713874.1483561636496
Content-Type: text/plain; charset=UTF-8

On Wednesday, January 4, 2017 at 2:54:36 AM UTC-8, D. B. wrote:
>
> I'm very interested in the resolution of that issue for the same reasons.
>
> Currently, by my understanding, the idea that any object can be read as a 
> "sequence" of ((un)signed) char* is not massively useful, when one 
> seemingly cannot iterate past the first element in that sequence... It then 
> means even memcpy cannot be implemented without special magic by the 
> compiler.
>

I think that the rule ought to be that char/unsigned char pointer 
arithmetic is valid so long as you don't leave the bounds (or 1 past end) 
of the dynamic type of the most-derived object.  Arithmetic with pointers 
of other types would be sketchy at best.

It ought to be legal to do this:

struct Meow
{
    int x;
    float y;
    int z;
};

void Function(Meow *meow)
{
    int *p = &meow.x;
    unsigned char *b = reinterpret_cast<unsigned char *>(p);
    b += offsetof(Meow, z) - (offsetof(Meow, x) + sizeof(meow->x));
    int *q = reinterpret_cast<int *>(b);  // OK because pointer is equal to 
a valid int * pointer
    *q = *p;   // same as meow->z = meow->x;
}


Melissa 

-- 
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/db74f34b-b0ab-46cb-b94a-eeb96ef10c2d%40isocpp.org.

------=_Part_2700_971713874.1483561636496
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">On Wednesday, January 4, 2017 at 2:54:36 AM UTC-8, D. B. w=
rote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8e=
x;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"><div>I&#=
39;m very interested in the resolution of that issue for the same reasons.<=
br><br></div>Currently, by my understanding, the idea that any object can b=
e read as a &quot;sequence&quot; of ((un)signed) char* is not massively use=
ful, when one seemingly cannot iterate past the first element in that seque=
nce... It then means even memcpy cannot be implemented without special magi=
c by the compiler.<br></div></blockquote><div><br>I think that the rule oug=
ht to be that char/unsigned char pointer arithmetic is valid so long as you=
 don&#39;t leave the bounds (or 1 past end) of the dynamic type of the most=
-derived object.=C2=A0 Arithmetic with pointers of other types would be ske=
tchy at best.<br><br>It ought to be legal to do this:<br><br><div style=3D"=
background-color: rgb(250, 250, 250); border-color: rgb(187, 187, 187); bor=
der-style: solid; border-width: 1px; overflow-wrap: break-word;" class=3D"p=
rettyprint"><code class=3D"prettyprint"><div class=3D"subprettyprint"><span=
 style=3D"color: #008;" class=3D"styled-by-prettify">struct</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"col=
or: #606;" class=3D"styled-by-prettify">Meow</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #008;" cl=
ass=3D"styled-by-prettify">int</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"> x</span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">;</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #008;" class=3D"styled-by=
-prettify">float</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"> y</span><span style=3D"color: #660;" class=3D"styled-by-prettify">;<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =
=C2=A0 </span><span style=3D"color: #008;" class=3D"styled-by-prettify">int=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> z</span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">};</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"><br><br></span><span style=3D"color: #008=
;" class=3D"styled-by-prettify">void</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"> </span><span style=3D"color: #606;" class=3D"sty=
led-by-prettify">Function</span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">(</span><span style=3D"color: #606;" class=3D"styled-by-pret=
tify">Meow</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
 </span><span style=3D"color: #660;" class=3D"styled-by-prettify">*</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify">meow</span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">)</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: =
#660;" class=3D"styled-by-prettify">{</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #=
008;" class=3D"styled-by-prettify">int</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">*</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify">p </span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">=3D</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">&amp;</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify">meow</span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">.</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify">x</span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">;</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #008=
;" class=3D"styled-by-prettify">unsigned</span><span style=3D"color: #000;"=
 class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D=
"styled-by-prettify">char</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">*</span><span style=3D"color: #000;" class=3D"styled-by-prettify">b <=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span styl=
e=3D"color: #008;" class=3D"styled-by-prettify">reinterpret_cast</span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><span styl=
e=3D"color: #008;" class=3D"styled-by-prettify">unsigned</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color=
: #008;" class=3D"styled-by-prettify">char</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">*&gt;(</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify">p</span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">);</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"><br>=C2=A0 =C2=A0 b </span><span style=3D"color: #660;" class=3D"styled-=
by-prettify">+=3D</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"> offsetof</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">(</span><span style=3D"color: #606;" class=3D"styled-by-prettify">Meo=
w</span><span style=3D"color: #660;" class=3D"styled-by-prettify">,</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"> z</span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">)</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">-</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">(</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify">offsetof</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">(</span><span style=3D"color: #606;" class=3D"styled-by-prettify">Meow<=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">,</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"> x</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">)</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">+</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by=
-prettify">sizeof</span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">(</span><span style=3D"color: #000;" class=3D"styled-by-prettify">me=
ow</span><span style=3D"color: #660;" class=3D"styled-by-prettify">-&gt;</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify">x</span><span=
 style=3D"color: #660;" class=3D"styled-by-prettify">));</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </span><sp=
an style=3D"color: #008;" class=3D"styled-by-prettify">int</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">*</span><span style=3D"color: #000;"=
 class=3D"styled-by-prettify">q </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-pr=
ettify">reinterpret_cast</span><span style=3D"color: #660;" class=3D"styled=
-by-prettify">&lt;</span><span style=3D"color: #008;" class=3D"styled-by-pr=
ettify">int</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">*&gt;(</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify">b</span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">);</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> =C2=A0</span><span style=3D=
"color: #800;" class=3D"styled-by-prettify">// OK because pointer is equal =
to a valid int * pointer</span><span style=3D"color: #000;" class=3D"styled=
-by-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">*</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify">q </span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">=3D</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
 </span><span style=3D"color: #660;" class=3D"styled-by-prettify">*</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify">p</span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"> =C2=A0 </span><span style=3D"color:=
 #800;" class=3D"styled-by-prettify">// same as meow-&gt;z =3D meow-&gt;x;<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">}</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"><br></span></div></code></=
div><br><br>Melissa <br></div></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/db74f34b-b0ab-46cb-b94a-eeb96ef10c2d%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/db74f34b-b0ab-46cb-b94a-eeb96ef10c2d=
%40isocpp.org</a>.<br />

------=_Part_2700_971713874.1483561636496--

------=_Part_2699_1556132105.1483561636496--

.
