"Wang,Yi" <netantz@xxxxxxxxx> 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@xxxxxxxxxxx rather than gcc-help@xxxxxxxxxxxx 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