What does it mean when a compiler says to allocate memory for variables at decreasing addresses?
What does it mean when a compiler says to allocate memory for variables at decreasing addresses?
Please paste the exact message, error numbers and all.
Jason Deckard
... and if it's not obvious from that info, tell us what compiler/OS you are using.
Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.
Well actually it is not a compiler error it is a question on a test I been taking. It shows a bit of code that have a fence post error on an array and ask what would happen if that piece of code is compiled and runed with a compiler that allocates memory for variables at decreasing addresses.
Since all variables are independent entities, there is no way to guarantee that any one variable will lie immediately before or after any other (even if you think you know whether its allocated up or down)
Given
int i, j;
Knowing &i tells you nothing about what &j will be.
For instance, you dont know
- which order the compiler allocates them in
- how much padding there might be between them
So predicting with any certainty what would happen with a fence post error is a pointless exercise.
Does this go for arrays to?Originally posted by Salem
Given
int i, j;
Knowing &i tells you nothing about what &j will be.
> Does this go for arrays to?
&arr[i] and &arr[j] can be compared - but this is only guarateed when both are within the bounds of the same array.