From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3534 invoked by alias); 24 Sep 2004 02:55:51 -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 3494 invoked from network); 24 Sep 2004 02:55:49 -0000 Received: from unknown (HELO merlin.cs.tamu.edu) (24.250.169.187) by sourceware.org with SMTP; 24 Sep 2004 02:55:49 -0000 Received: by merlin.cs.tamu.edu (Postfix, from userid 500) id 5DEA43558F; Thu, 23 Sep 2004 21:55:49 -0500 (CDT) To: "Giovanni Bajo" Cc: "Joseph S. Myers" , Subject: Re: attribute data structure rewrite References: <006d01c4a1dd$ffc60b70$dc4e2a97@bagio> <00cf01c4a1e0$bf25faa0$dc4e2a97@bagio> From: Gabriel Dos Reis In-Reply-To: <00cf01c4a1e0$bf25faa0$dc4e2a97@bagio> Organization: Texas A&M University, Department of Computer Science Date: Fri, 24 Sep 2004 04:18:00 -0000 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-SW-Source: 2004-09/txt/msg01397.txt.bz2 "Giovanni Bajo" writes: | Gabriel Dos Reis wrote: | | > We used to accept it because we did not implement offsetof correctly. | > For example, the following variation should be rejected (in C89 an C++ | > mode) | > | > struct A { char foo[10]; }; | > void bar(void) { | > int i; | > for (int i = 0; i < 10; ++i) | > { | > char ary[offsetof(struct A, foo[i] + 1); | > } | > } | | I don't understand your example because I don't think the +1 there is valid. | Unless you meant: | | char ary[offsetof(struct A, foo[i])+1]; Yes, this is what I meant. Sorry for the typo, and sending a testcase without compiling :-) | Anyway, what about this in C99? Even in strict C99 mode, it will not be valid. One could think of GNU extensions that compute offsetof at run-time, but that is something we've debated much in the past. I see the move to the new implementation as a desire to keep away from that. RTH might want to weight in. | We don't need a constant expression in this | context, and even if offsetof is always a constant expression we could still | accept it as an extension. I agree that in C99, one does not need a constant expression to make it work, but the offsetof-subexpression still will not be valid. | In other words, we could transform it to | offsetof(struct A, foo)+i*sizeof(foo[0]) in contexts that don't require a | constant expression. That is a possibility. I'm not sure how serious the issue is. -- Gaby