arithmetics of indicators
-
Question of the arithmetics of indicator C. Let
int *p; int *q; int *o; int i; o = NULL;
Let right.
p
andq
points to the different elements of the same body. Permissibility of expression (i, naturally, is defined):p+i; q-i; p-q;
Is it permissible to:
p-o; o-p;
What happens if you're allowed? On the one hand
o
It doesn't point to the same body, and it doesn't, but it's also normal.0
and the first one, I think so.
-
No, not allowed♪
Standard C++ says http://eel.is/c++draft/expr.add#5 that if the two indicators do not belong to one body, the conduct is not defined.
The result of the deduction of the two indexes is the number of elements between them. If
p
Not flatsizeof(int)
the expressionp-o
must return the fragmented number of elements that cannot be.The expression
p-NULL
It could only be true ifNULL
- That's it.#define NULL 0
and not valid if, for example,NULL
defined as(void*)0
(in C). Since the standard does not indicate how to be definedNULL
it should be assumed that the expressionp-NULL
No, it's not.Note: expression
p-0
Alive and stillp
but it only works for a whole number0
♪