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

ARM different array size by complier

I faced the wired situation.
I have two questions.

I declared the global variable of structure array type as below.
A_TYPE gstXXXX[16];

Then, two functions wanted to look for the address of gstXXXX[1].

Q1)
At first function, the address of gstXXX[1] was &gstXXX[0]+1464. But other funtion calculated the address of gstXXX[1] was &gstXXX[0]+1480.

Q2)
I declared three structures by the same type.
typedef struct A { }
typedef struct B { }
typedef struct C { }

But the result of sizeof them are different.
sizeof(A)=124, sizeof(B)=140, sizeof(C)=124

What happened?
I cannot understand them.

Please let me know something, if u have ever experienced this problem.

Parents
  • Q1)
    At first function, the address of gstXXX[1] was &gstXXX[0]+1464. But other funtion calculated the address of gstXXX[1] was &gstXXX[0]+1480.

    So the definitions of your A_TYPE data structure seen by those two functions are different.

    I declared three structures by the same type.
    typedef struct A { }
    typedef struct B { }
    typedef struct C { }

    No, you didn't, because none of those is a declaration of any type. They're all syntax errors.

    But the result of sizeof them are different.
    sizeof(A)=124, sizeof(B)=140, sizeof(C)=124

    What happened?

    It's really quite obvious: despite your statement, they're not the same type. You made it impossible to find out what the difference actually is by stripping out all the details. Come back here with a reproducible example, and odds are people will be able to point you to the exact difference.

Reply
  • Q1)
    At first function, the address of gstXXX[1] was &gstXXX[0]+1464. But other funtion calculated the address of gstXXX[1] was &gstXXX[0]+1480.

    So the definitions of your A_TYPE data structure seen by those two functions are different.

    I declared three structures by the same type.
    typedef struct A { }
    typedef struct B { }
    typedef struct C { }

    No, you didn't, because none of those is a declaration of any type. They're all syntax errors.

    But the result of sizeof them are different.
    sizeof(A)=124, sizeof(B)=140, sizeof(C)=124

    What happened?

    It's really quite obvious: despite your statement, they're not the same type. You made it impossible to find out what the difference actually is by stripping out all the details. Come back here with a reproducible example, and odds are people will be able to point you to the exact difference.

Children
No data