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

Memory layout of variables not in order of declaration

Using uVision 5.12.0.0 (ARM)
I need my variables to be placed in the order I declare them.
But when I look at the map-file they are not.
The types I use are unsigned) char, (unsigned) int, and arrays of these types.

Question 1: How are variables placed in memory?
Question 2: How can I control the order, there is no #pragma ORDER (as was in C166)?
Question 3: Any alternatives, besides placing them in a structure?

Thanks.

Parents
  • Sorry, I'm not sure how they are ordered, but have you checked if the compiler rearranges them to maintain alignment without excess padding? And are you sure the compiler did rearrange the order and did not just add padding?

    Having an int, a char and an int after each other would require three bytes of padding to get the second int properly aligned.

Reply
  • Sorry, I'm not sure how they are ordered, but have you checked if the compiler rearranges them to maintain alignment without excess padding? And are you sure the compiler did rearrange the order and did not just add padding?

    Having an int, a char and an int after each other would require three bytes of padding to get the second int properly aligned.

Children