From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26423 invoked by alias); 10 Sep 2014 23:03:55 -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 26412 invoked by uid 89); 10 Sep 2014 23:03:54 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.1 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: nm3-vm0.bullet.mail.bf1.yahoo.com Received: from nm3-vm0.bullet.mail.bf1.yahoo.com (HELO nm3-vm0.bullet.mail.bf1.yahoo.com) (98.139.212.154) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Wed, 10 Sep 2014 23:03:53 +0000 Received: from [66.196.81.170] by nm3.bullet.mail.bf1.yahoo.com with NNFMP; 10 Sep 2014 23:03:51 -0000 Received: from [98.139.212.230] by tm16.bullet.mail.bf1.yahoo.com with NNFMP; 10 Sep 2014 23:03:51 -0000 Received: from [127.0.0.1] by omp1039.mail.bf1.yahoo.com with NNFMP; 10 Sep 2014 23:03:51 -0000 Received: (qmail 35946 invoked by uid 60001); 10 Sep 2014 23:03:51 -0000 Received: from [98.115.82.36] by web140202.mail.bf1.yahoo.com via HTTP; Wed, 10 Sep 2014 16:03:51 PDT Message-ID: <1410390231.39617.YahooMailNeo@web140202.mail.bf1.yahoo.com> Date: Wed, 10 Sep 2014 23:03:00 -0000 From: haynberg@yahoo.com Reply-To: haynberg@yahoo.com Subject: RE: is portable aliasing possible in C++? To: "aph@redhat.com" , "gcc-help@gcc.gnu.org" MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-SW-Source: 2014-09/txt/msg00067.txt.bz2 > > So it would seem the answer is no, portable aliasing is not possible > > in C++. Though I wonder if it should be (with a new language > > feature). > > In practice, a union is exactly that, and I've not heard of a compiler > which doesn't do the right thing. Given that it's explicitly legal in > C11, I can't see any reason which C++ shouldn't simply adopt the same > language. I agree. But in the union case, you're copying bytes. If you don't perform a copy, for example: struct msg { // ... }; char *get_bytes(); msg *p = reinterpret_cast(get_bytes()); if (p->i) // ... Then there can't be a portable way to do this, because there's hardware that doesn't permit unaligned reads (e.g. where you'd get a SIGBUS). So I guess I retract that "I wonder if" part :-) Jay Haynberg