gcc --version
gcc (GCC) 4.8.1

(4.7.2 seems to work)

gcc -g -fPIC -O2 -Wall -o test test.c

./test
type_a is 0x0

Correct would be 0x14000. I don't see how the C-code could be
ambiguous, I think this is a bug?

test.c:

#include <stdio.h>

typedef struct
{
    unsigned int a:4;
    unsigned int b:5;
    unsigned int c:5;
    unsigned int d:18;
} my_comb_t;

struct my_s
{
    int l;
};

my_comb_t *getps_f (struct my_s *a);

#define GETPS(x) getps_f(&(x))

my_comb_t *
getps_f (struct my_s *a)
{
  my_comb_t *p = (my_comb_t *) &(a->l);
  return p;
}

int g_modes = 5;

int main(void)
{
    int modes = g_modes;
    int type_a = 0;

    if (modes)
    {
        struct my_s m;
        m.l = type_a;
        my_comb_t *p = GETPS(m);
        p->d |= modes;
        type_a = m.l;
    }
    printf("type_a is 0x%x\n", type_a);
    return 0;
}

Regards,
Hendrik Greving

Reply via email to