From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29816 invoked by alias); 9 Sep 2014 23:13:04 -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 29788 invoked by uid 89); 9 Sep 2014 23:13:00 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 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: nm2-vm1.bullet.mail.bf1.yahoo.com Received: from nm2-vm1.bullet.mail.bf1.yahoo.com (HELO nm2-vm1.bullet.mail.bf1.yahoo.com) (98.139.213.158) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Tue, 09 Sep 2014 23:12:59 +0000 Received: from [66.196.81.172] by nm2.bullet.mail.bf1.yahoo.com with NNFMP; 09 Sep 2014 23:12:57 -0000 Received: from [98.139.212.221] by tm18.bullet.mail.bf1.yahoo.com with NNFMP; 09 Sep 2014 23:12:56 -0000 Received: from [127.0.0.1] by omp1030.mail.bf1.yahoo.com with NNFMP; 09 Sep 2014 23:12:56 -0000 Received: (qmail 8231 invoked by uid 60001); 9 Sep 2014 23:12:56 -0000 Received: from [98.115.82.36] by web140202.mail.bf1.yahoo.com via HTTP; Tue, 09 Sep 2014 16:12:56 PDT Message-ID: <1410304376.4232.YahooMailNeo@web140202.mail.bf1.yahoo.com> Date: Tue, 09 Sep 2014 23:13:00 -0000 From: haynberg@yahoo.com Reply-To: haynberg@yahoo.com Subject: Re: is portable aliasing possible in C++? To: "gcc-help@gcc.gnu.org" MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-SW-Source: 2014-09/txt/msg00053.txt.bz2 Using reinterpret_cast to convert between unrelated pointer types is a language feature that, by definition, makes your code not portable (assuming you dereference). While it's undefined by the standard, that doesn't mean it's undefined for a given platform (OS/compiler/compiler options). For example, on an architecture which allows unaligned reads and the compiler does not perform strict-aliasing optimizations, it's likely OK (e.g. MS or Clang on x86). If the compiler does perform those optimizations and provides a way to programmatically disable them (like GCC's may_alias) and you make use of that feature correctly, it's also likely OK. But if the compiler does perform those optimizations and it doesn't provide something like may_alias, then it is undefined, and you have no choice but to disable the optimization for the whole program or resort to memcpy. 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). Jay Haynberg