B
braton
Hello
I'm wondering about the following thing:
Let's define variable and set a pointer to points to it:
int a = 0;
int * p_a = &a;
Now, according to C99, clause 6.5.6.7 I can treat pointer to "a"
like a pointer to the first element of the array of length 1 for
the purpose of additive operators. So after:
p_a++;
my pointer points to one past last element of the array and
it seems to be ok. But what about the following next statement:
++p_a;
I found the following part of clause 8 a bit unclear:
"If both the pointer operand and the result point to elements of the
same
array object, or one past the last element of the array object, the
evaluation
shall not produce an overflow; otherwise, the behavior is undefined."
The question is:
the behaviour is undefined when I just incremented pointer more than
one past last
element of the array or it is undefined when I dereference such
incremented pointer.
If the former could somebody give an example of architecture where
just setting
pointer that way produces some sort of exception.
Thanks for your help
I'm wondering about the following thing:
Let's define variable and set a pointer to points to it:
int a = 0;
int * p_a = &a;
Now, according to C99, clause 6.5.6.7 I can treat pointer to "a"
like a pointer to the first element of the array of length 1 for
the purpose of additive operators. So after:
p_a++;
my pointer points to one past last element of the array and
it seems to be ok. But what about the following next statement:
++p_a;
I found the following part of clause 8 a bit unclear:
"If both the pointer operand and the result point to elements of the
same
array object, or one past the last element of the array object, the
evaluation
shall not produce an overflow; otherwise, the behavior is undefined."
The question is:
the behaviour is undefined when I just incremented pointer more than
one past last
element of the array or it is undefined when I dereference such
incremented pointer.
If the former could somebody give an example of architecture where
just setting
pointer that way produces some sort of exception.
Thanks for your help