From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11830 invoked by alias); 11 Sep 2014 23:25:43 -0000 Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org Received: (qmail 11819 invoked by uid 89); 11 Sep 2014 23:25:42 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.6 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,RP_MATCHES_RCVD,SPF_PASS autolearn=ham version=3.3.2 X-HELO: nm17-vm1.bullet.mail.bf1.yahoo.com Received: from nm17-vm1.bullet.mail.bf1.yahoo.com (HELO nm17-vm1.bullet.mail.bf1.yahoo.com) (98.139.213.55) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Thu, 11 Sep 2014 23:25:41 +0000 Received: from [98.139.212.149] by nm17.bullet.mail.bf1.yahoo.com with NNFMP; 11 Sep 2014 23:25:39 -0000 Received: from [98.139.212.224] by tm6.bullet.mail.bf1.yahoo.com with NNFMP; 11 Sep 2014 23:25:39 -0000 Received: from [127.0.0.1] by omp1033.mail.bf1.yahoo.com with NNFMP; 11 Sep 2014 23:25:39 -0000 Received: (qmail 56867 invoked by uid 60001); 11 Sep 2014 23:25:39 -0000 Received: from [98.115.82.36] by web140205.mail.bf1.yahoo.com via HTTP; Thu, 11 Sep 2014 16:25:38 PDT References: <1410390231.39617.YahooMailNeo@web140202.mail.bf1.yahoo.com> <54115917.1040602@redhat.com> Message-ID: <1410477938.56522.YahooMailNeo@web140205.mail.bf1.yahoo.com> Date: Thu, 11 Sep 2014 23:25:00 -0000 From: haynberg@yahoo.com Reply-To: haynberg@yahoo.com Subject: Re: is portable aliasing possible in C++? To: Andrew Haley , "gcc-help@gcc.gnu.org" In-Reply-To: <54115917.1040602@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-SW-Source: 2014-09/txt/msg00071.txt.bz2 >> msg *p =3D reinterpret_cast(get_bytes()); > > Why are you doing this? For efficiency, by preventing a copy (imagine get_bytes() is getting bytes = out of a socket buffer).=20=20 Putting alignment/padding concerns aside, it would be nice if there was a w= ay to explicitly tell the compiler, I want to do this and, please don=E2=80= =99t reorder stores and loads, or perform other strict-aliasing optimizatio= ns, on the memory pointed to by this pointer (similar to the effect of a me= mcpy). I believe the only way to do this is with the GCC may_alias attribu= te, or a more heavy-handed memory clobber. I think the OP wanted to ask th= e GCC folks if there was another, possibly more portable, way; for example,= placement new, but that turned out not to be an option.=20 Another related, maybe more important, question is if GCC sees a reinterpet= _cast like this (without a may_alias type), is it free to discard code or o= therwise drastically change it due to the fact that it=E2=80=99s undefined = by the standard? Like some of the cases shown in: =E2=80=9Cany undefined behavior in C gives license to the implementation (t= he compiler and runtime) to produce code that ... does completely unexpecte= d things, or worse=E2=80=9D http://blog.llvm.org/2011/05/what-every-c-programmer-should-know.html Jay Haynberg