If you declare severable variables in order, will they have incrementing addresses

79 views Asked by At

We have a c program with a lot of files and we are wondering one specific thing.

We are compiling it with C51.

If, lets say in one of the files, I declare a few variables like:

unsigned char xdata a;
unsigned char xdata b;
...
//etc
unsigned char xdata z;

Will their addresses be incrementing and in the same order? as they are declared?

I realize that incrementing addresses can be achieved using arrays or structs or that I can assign fixed addresses of choice but that is not the question.

1

There are 1 answers

0
Lundin On

Will their addresses be incrementing and in the same order? as they are declared?

No, you can't know or assume anything about this. They may be allocated in any order on the stack, or in registers, or not allocated at all. The only time when allocation order is guaranteed is when declaring arrays and structs.

In addition, you can't use pointer arithmetic on anything that's not an array, or you risk running into various subtle undefined behavior bugs.