public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* order of declared filed in a struct
@ 2006-06-15 20:40 Wang,Yi
  2006-06-16  6:44 ` Ian Lance Taylor
  0 siblings, 1 reply; 2+ messages in thread
From: Wang,Yi @ 2006-06-15 20:40 UTC (permalink / raw)
  To: gcc-help

Hi all:

 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.
-----------------------------


Thanks

-- 
Yi Wang
Software Engineering, ComSci@U of T

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: order of declared filed in a struct
  2006-06-15 20:40 order of declared filed in a struct Wang,Yi
@ 2006-06-16  6:44 ` Ian Lance Taylor
  0 siblings, 0 replies; 2+ messages in thread
From: Ian Lance Taylor @ 2006-06-16  6:44 UTC (permalink / raw)
  To: netantz; +Cc: gcc-help

"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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2006-06-16  6:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-06-15 20:40 order of declared filed in a struct Wang,Yi
2006-06-16  6:44 ` Ian Lance Taylor

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).