From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14054 invoked by alias); 16 Jun 2006 06:44:55 -0000 Received: (qmail 14045 invoked by uid 22791); 16 Jun 2006 06:44:54 -0000 X-Spam-Check-By: sourceware.org Received: from fencepost.gnu.org (HELO fencepost.gnu.org) (199.232.76.164) by sourceware.org (qpsmtpd/0.31) with ESMTP; Fri, 16 Jun 2006 06:44:53 +0000 Received: from monty-python.gnu.org ([199.232.76.173]) by fencepost.gnu.org with esmtp (Exim 4.34) id 1Fr84R-0004Qp-CR for gcc-help@gnu.org; Fri, 16 Jun 2006 02:44:43 -0400 Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.52) id 1Fr8Dw-0000NN-BU for gcc-help@gnu.org; Fri, 16 Jun 2006 02:54:34 -0400 Received: from [216.239.45.12] (helo=smtp-out.google.com) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA:32) (Exim 4.52) id 1Fr8Dv-0000Mq-KJ for gcc-help@gnu.org; Fri, 16 Jun 2006 02:54:32 -0400 Received: from vegeta.corp.google.com (vegeta.corp.google.com [172.24.0.3]) by smtp-out.google.com with ESMTP id k5G6iDmE018503; Thu, 15 Jun 2006 23:44:14 -0700 Received: from smtp.google.com (mordor.corp.google.com [192.168.15.226]) by vegeta.corp.google.com with ESMTP id k5G6i6i3013210 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 15 Jun 2006 23:44:06 -0700 Received: from localhost.localdomain.google.com (adsl-71-133-8-30.dsl.pltn13.pacbell.net [71.133.8.30]) (authenticated bits=0) by smtp.google.com (8.13.6/8.13.6) with ESMTP id k5G6i4pt020200 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Thu, 15 Jun 2006 23:44:06 -0700 To: netantz@gmail.com Cc: gcc-help@gnu.org Subject: Re: order of declared filed in a struct References: <9aff10810606151340p29fb13adm56e21c2e685f1aee@mail.gmail.com> From: Ian Lance Taylor Date: Fri, 16 Jun 2006 06:44:00 -0000 In-Reply-To: <9aff10810606151340p29fb13adm56e21c2e685f1aee@mail.gmail.com> Message-ID: User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.4 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-IsSubscribed: yes Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org X-SW-Source: 2006-06/txt/msg00131.txt.bz2 "Wang,Yi" writes: > In the GIMPLE tree, How do I get the order of the field declared in a > struct (RECORD_TYPE) ? The GCC Internal explains that I could not make > any assumptions abut the ordering of th field. > > > ------------------------------- > RECORD_TYPE > Used to represent struct and class types, as well as pointers to > member functions and similar constructs in other languages. > TYPE_FIELDS contains the items contained in this type, each of which > can be a FIELD_DECL, VAR_DECL, CONST_DECL, or TYPE_DECL. You may not > make any assumptions about the ordering of the fields in the type or > whether one or more of them overlap. If TYPE_PTRMEMFUNC_P holds, then > this type is a pointer-to-member type. In that case, the > TYPE_PTRMEMFUNC_FN_TYPE is a POINTER_TYPE pointing to a METHOD_TYPE. > The METHOD_TYPE is the type of a function pointed to by the > pointer-to-member function. If TYPE_PTRMEMFUNC_P does not hold, this > type is a class type. For more information, see see Classes. > ----------------------------- It's OK to send detailed questions about gcc data structures to gcc@gcc.gnu.org rather than gcc-help@gcc.gnu.org. The RECORD_TYPE has a list of FIELD_DECLs. Each FIELD_DECL has DECL_FIELD_BIT_OFFSET to indicate the bit offset of the field within the record. The width can be found in DECL_SIZE. Given that information, you can sort the fields if you want to. C guarantees that the fields will be laid out in the order in which they are declared in the struct, so for C the order in memory is the same as the order specified by the programmer. Ian