From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28064 invoked by alias); 26 Dec 2002 23:46:01 -0000 Mailing-List: contact gcc-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-prs-owner@gcc.gnu.org Received: (qmail 28050 invoked by uid 71); 26 Dec 2002 23:46:01 -0000 Date: Thu, 26 Dec 2002 15:46:00 -0000 Message-ID: <20021226234601.28049.qmail@sources.redhat.com> To: nobody@gcc.gnu.org Cc: gcc-prs@gcc.gnu.org, From: Manfred Spraul Subject: Re: c/9058: structure with flexible array member: offsetof() != sizeof() Reply-To: Manfred Spraul X-SW-Source: 2002-12/txt/msg01304.txt.bz2 List-Id: The following reply was made to PR c/9058; it has been noted by GNATS. From: Manfred Spraul To: "Joseph S. Myers" Cc: gcc-gnats@gcc.gnu.org, gcc-bugs@gcc.gnu.org Subject: Re: c/9058: structure with flexible array member: offsetof() != sizeof() Date: Fri, 27 Dec 2002 00:37:54 +0100 Joseph S. Myers wrote: >On Thu, 26 Dec 2002, Manfred Spraul wrote: > > > >>Thanks, I found the thread "C99 conformance bug in gcc-3.1" after filing >>the bug report. >>What's the recommended approach to calculate the size for malloc calls? Is >> >> struct a {int a; char b; short c[]; }; >> >> len = offsetof(struct a, c[nr_entries]); >> >> > >You mean offsetof(struct a, c) + nr_entries * sizeof(short). > > No, I meant what I wrote - is that valid? It would be less error prone, e.g. if the type of the flexible array member is changed. linux kernel, i.e gcc portability across platforms. -- Manfred