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

How many byte(s)/bits is U8 - char, U16...

This seem just dummy question.

What is a problem. I have some old project, that works on 8 bit prosecos. Now I reforming for arm7 procesor.

Ok, I find out, that in old procesor is int 16 bit type, in arm is 32 bit type, no problem. In rtl.h are definitions like U32 as unsigned int, ... and on the and U8 as unsigned char. Sizeof(U8) is 1 - 1 byte (8 bit).

Than i define my own structure for exaple:

typedef struct
{
    U8   byte_1;
    U16  bytes_2;
} MY_STRUCTURE;

sizeof(MY_STRUCTURE) is 4!!! How could be this posible?

Parents
  • You can see the effect of the alignment padding byte by adding a second byte, e.g.

    typedef struct
    {
        U8   byte_1;
        U8   byte_2;
        U16  bytes_2;
    } MY_NEW_STRUCTURE;
    

    sizeof(MY_NEW_STRUCTURE) may now be 4, or it may be 6! It's one of those C compiler implementation things you just need to learn about.

Reply
  • You can see the effect of the alignment padding byte by adding a second byte, e.g.

    typedef struct
    {
        U8   byte_1;
        U8   byte_2;
        U16  bytes_2;
    } MY_NEW_STRUCTURE;
    

    sizeof(MY_NEW_STRUCTURE) may now be 4, or it may be 6! It's one of those C compiler implementation things you just need to learn about.

Children
No data