This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

attribute(at)


Hello,

Often it's needed to specify an exact memory layout of a data
structure -- this feature is useful for low-level programmers,
because most hardware-dependent structures have exactly
specified member offsets. Currently it's necessary to use
ugly tricks, for example:

typedef struct {

    CHAR m_FieldAlignment[5];
    UINT32 m_Field;

}  __attribute__((packed))  XXX;

Here's a simple proposition of a new extension of the GCC
compiler. Usage:

#define AT(x) __attribute__((at(x)))

struct {

    UINT32 m_Field AT(10);
    CHAR m_SecondField[14] AT(1547);

} PACKED XXX;

Meaning: a field which has the attribute specified is placed
exactly at the offset (in other words: relatively to the structure's
base address, when the strcture is instantiated). Can be used
in nested structures:

struct {
    
    UINT32 m_X AT(0);

    struct {

        UINT64 m_Y AT(10);
    } Y;
} X;

X's ofset is 0, Y's offset is 14 (=sizeof(UINT32) + 10).

Is it possible to include this simple but very useful mechanism
to the future releases of GCC? I think that many low-level
developers would be very happy because of this extension.
This attribute could be also used by code written in C++,
when applied to a POD structure.

    Best regards
    Piotr Wyderski
   


Serwis www.logo.hoga.pl - sciagaj bajery na telefony
Nokia, Siemens, Alcatel, Ericsson, Motorola,Samsung
------------------------------------------------------------
Promocja!!! rabat 40 % na zakup mks_vir 2003 dla klientów Connect , którzy
posiadaja kupony rabatowe.



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]