public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Ian Lance Taylor <iant@google.com>
To: netantz@gmail.com
Cc: gcc-help@gnu.org
Subject: Re: order of declared filed in a struct
Date: Fri, 16 Jun 2006 06:44:00 -0000	[thread overview]
Message-ID: <m3slm5eh1p.fsf@localhost.localdomain> (raw)
In-Reply-To: <9aff10810606151340p29fb13adm56e21c2e685f1aee@mail.gmail.com>

"Wang,Yi" <netantz@gmail.com> 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

      reply	other threads:[~2006-06-16  6:44 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-06-15 20:40 Wang,Yi
2006-06-16  6:44 ` Ian Lance Taylor [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m3slm5eh1p.fsf@localhost.localdomain \
    --to=iant@google.com \
    --cc=gcc-help@gnu.org \
    --cc=netantz@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).