#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    28
    Rep Power
    0

    [gcc] attribute aligned


    Hello,

    I am a beginner in C, et i have some problem understanding the aligned attribute of gcc.

    ex <type> x __attribute__((aligned(nb_bytes))));

    (x is the name of the variable, type is its type, and nb_bytes the number of byte to align ).

    I test on a solaris machine,
    and for example.

    i do :
    char x __attribute__((aligned(4)));
    but the adress of x (&x), is never like &x % 4 == 0
    why ???

    and what can be the maximun size of aligned (is it the max size of memory that the proc can take in 1 clock ?? )

    thanks for your help
    Sylvain
  2. #2
  3. Contributing User

    Join Date
    Aug 2003
    Location
    UK
    Posts
    5,117
    Rep Power
    1803
    The manual says:

    Note that the effectiveness of aligned attributes may be limited by inherent limitations in your linker. On many systems, the linker is only able to arrange for variables to be aligned up to a certain maximum alignment. (For some linkers, the maximum supported alignment may be very very small.) If your linker is only able to align variables up to a maximum of 8 byte alignment, then specifying aligned(16) in an __attribute__ will still only provide you with 8 byte alignment. See your linker documentation for further information.
    http://gcc.gnu.org/onlinedocs/gcc-3....e%20Attributes

    Maybe?

    Try a structure with two char memebers aligned at 4 (or other values), what is the address of these?

    Clifford
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    28
    Rep Power
    0
    hello,

    i have done :
    x __attribute__((aligned(128)));

    => &x == effff14a
    if i put aligned (4), i have the same address !!
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    28
    Rep Power
    0
    in fact, i precise that I compile in solaris/sun station.

    which is big endian, so :
    int x is 4 bytes long.
    &x is the adress of the MSB.
    the adress of the LSB is greater than the adresse of the MSB.

IMN logo majestic logo threadwatch logo seochat tools logo