something to warry about...

Sergey Naumov sknaumov at gmail.com
Tue Jan 18 08:23:16 UTC 2011


> I need a concrete example how to make warning go away in this case:
>
> static smallint detect_link_priv(void)
> {
>        struct ifreq ifreq;
>        struct mii_ioctl_data *mii = (void *)&ifreq.ifr_data;
> ...
>        mii->reg_num = 1;
>

> Can we redeclare structures with __attribute__(__may_alias__)?
> No, because they are already declared.

Denys, here is text from the GCC manual:

may_alias
      Example of use:

              typedef short __attribute__((__may_alias__)) short_a;

              int main (void)
              {
                int a = 0x12345678;
                short_a *b = (short_a *) &a;
                b[1] = 0;
                if (a == 0x12345678)
                  abort();
                exit(0);
              }

    If you replaced short_a with short in the variable declaration,
the above program would abort when compiled with -fstrict-aliasing,
which is on by default at -O2 or above in recent GCC versions.


So try to
static smallint detect_link_priv(void)
{
    typedef struct mii_ioctl_data __attribute__((__may_alias__)) mii_alias;
    struct ifreq ifreq;
    mii_alias *mii = (void *)&ifreq.ifr_data;
    ...
    mii->reg_num = 1;

Hope that this will help,

Sergey Naumov.


More information about the busybox mailing list