This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

What mistake I am doing here in C code

I wrote following code

typedef union
{
    struct
    {
        int8_t   a;
        int16_t  b;
        uint32_t c;
    };

    int8_t my_arr[7];
}x;

uint8_t arr[7];

int main( void )
{
    uint32_t i;
    x *y;

    for( i = 0 ; i < 7 ; i++ )
    {
        arr[i] = i + 2 * 5;
    }

    y = ( x* )arr;

    i = y->a;
    i = y->b;
    i = y->c;
}



End result in Y is:
a = 0x0a;
b = 0x0d0c
c = 0x00100F0E
my_arr[0-7] = 0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0x10;

& array conatisn
arr[0-7] = 0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0x10;

My question is when a= 0x0a , then should be b = 0x0c0b & c = 0x100f0e0d
but this is not the case

I am using keil 4.70.0.0, mdk arm

0