From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2816 invoked by alias); 9 Dec 2004 22:54:16 -0000 Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org Received: (qmail 2781 invoked from network); 9 Dec 2004 22:54:12 -0000 Received: from unknown (HELO sccrmhc13.comcast.net) (204.127.202.64) by sourceware.org with SMTP; 9 Dec 2004 22:54:12 -0000 Received: from [10.0.1.2] (h000393256f12.ne.client2.attbi.com[24.61.199.96]) by comcast.net (sccrmhc13) with SMTP id <2004120922541201600smnfue>; Thu, 9 Dec 2004 22:54:12 +0000 User-Agent: Microsoft-Entourage/11.1.0.040913 Date: Thu, 09 Dec 2004 22:54:00 -0000 Subject: Re: memcpy / Language Lawyer / optimization question From: Paul Schlie To: Message-ID: Mime-version: 1.0 Content-type: text/plain; charset="US-ASCII" Content-transfer-encoding: 7bit X-SW-Source: 2004-12/txt/msg00341.txt.bz2 > Joseph S. Myers wrote: >> On Thu, 9 Dec 2004, Steve Ellcey wrote: >> My question is about the second memcpy where I cast to (void *). This >> still results in an abort on IA64 because it is still assuming integer >> alignment (and thus changing the code to do an integer assignment). Is >> it legal to do this transformation with the (void *) cast? > > The casts in the calls to memcpy are irrelevant: the undefined behavior > occurs before them, at the point where you cast an unaligned pointer to > int *. Casting a pointer to another pointer type for which it doesn't > have the alignment yields undefined behavior. The compiler can assume > that the result of a sequence of pointer casts has the alignment of > whichever type in the sequence of pointer types has the strictest > alignment requirements. As a more general but related question: as C does not define/specify everything, and even occasionally specifies something as being explicitly "unspecified", giving license to the complier to express whatever incidental behavior it may have; has the GCC team adopted the strategy that it will strive to adopt and document the behavior which seems most generally useful and/or least-fragile in such circumstances (which it has license to do), as opposed to justifying any such behavior as being "legal" without regard to the consideration of adopting a more useful behavior, and/or emit warnings if the adopted behavior may have undesirable consequences when reasonable to do so; or is this also "unspecified"? :)