Edit to add: although g++ didn't compile the program at all -- "pointer of type 'void *' used in arithmetic" is an error, not a warning, to g++.
Indeed. I only tried it with GCC . . . . I didn't even think try to it as C++, because I though ptrdiff_t was C99-only.
I know you hate command lines, but bear with me here.
Code:
$ cat ppvoid.cpp
#include <iostream>
int main() {
void *a, *b;
a = &b;
b = &a;
return 0;
}
$ g++ -W -Wall -ansi -pedantic ppvoid.cpp -o ppvoid
$
No warnings at all.
It's true that something like this is invalid
Code:
void *p = 0;
void **pp = p; // error: invalid conversion from ‘void*’ to ‘void**’
but the code I used above compiles for some reason. Another thing:
Code:
void ***ppp = 0;
void **pp = ppp; // g++ doesn't like this
void *p = pp; // but is fine with this
Anyway . . . .
2) As far as the compiler is concerned, you're not adding pointers. You're subtracting pointers, yielding an integer, and you're subtracting an integer from a pointer, yielding a pointer.
That's true.
3) Why the complicated negate stuff?
I have no idea.