This is actually a fairly simple thing to answer.
All you are doing is pointer math, there is nothing invalid about it. If you try to USE the resulting pointers in some way then depends on whether or not your process has access to the memory pointed to by that pointer, and if so what are the permissions on it?
foo.cc:
#include <iostream>
using namespace std;
int main() {
int array[10];
int *a = array + 10;
int *b = &array[10];
int *c = &array[3000];
cerr << "Pointers values are: " << a << " " << b << " " << c << endl;
return 0;
}
g++ -Werror -Wall foo.cc -o foo
should yield NO warnings because the int *b = &array[10] is valid
Actually so is the subsequent line added by me to just point something out about pointer math.
not only will foo compile, it will run without a hitch:
./foo
Pointers are: 0x7fff1d356e68 0x7fff1d356e68 0x7fff1d359d20
I'll post Visual C++ output as soon as my VM boots :-)
Basically array syntax foo[idx] is short cut and clean representation of pointer math.
In case there is some confusion regarding c99, the standard DOES NOT affect this math in anyway and well defined.
The same thing in C99:
#include <stdio.h>
int main() {
int array[10];
int *a = array + 10;
int *b = &array[10];
int *c = &array[3000];
fprintf(stderr, "Pointers are: %p, %p, %p\n" , a , b , c );
return 0;
}
gcc -std=c99 -Wall -Werror -o foo foo.c
./foo
Pointers are: 0x7fff2c7d22c8, 0x7fff2c7d22c8, 0x7fff2c7d5180