A
ark
bq said:In the code
int a[17];
int b = -1;
does ANSI C guarantee that "b" is located in memory right after "a[16]"
so that "a[17]" refers to "b"?
Thanks.
bq
Since a and b belong (whatever th official terminology) to different
categories -- uninitialized and initialized data respectively, a compiler
may have sound reasons to put them in different, e.g., named segments, to
optimize the startup code, for instance.
However, if both are initialized (int a=1,b=-1 or both are not (int a,
b, both are arrays or both are not (and both have identical types and
qualifiers) it is rather hard to imagine reasons why a compiler would prefer
an allocation different from the order of occurrence. (For the heck of it,
it could be the opposite order, but then it would break some existing code,
would it not?
Now, the standard quoting in this thread... undefined behavior and such...
If a function receives an int *, it has no idea where it came from, so it
(function) must allow adding any int to it (pointer). (As is usual in C, it
is the programmer's job to care about overflows.) So this "undefinedness"
looks like a lip service.
I wonder if I am correct in this assessment and also if indeed for all
practical purposes (&a+1==&b) holds true for statements <qual><type>a;
<qual><type>b;?
Thanks
- Ark