The other day I thought "I'm finally gonna dive deep into C++, and I'm going to start out right, with a mindset toward modern C++ and statically forbidding memory errors, etc."
First thing I did was write up a test program that looks something like this, to see what errors I would get:
int x = 42;
int* px = &x;
px++;
*px = 12;
Compiled on GCC with -Wall. No warnings. I thought for sure some warning must prevent pointer arithmetic. After asking around I guess what I did above wasn't really pointer arithmetic, at least not in the compiler's eyes, so it's not warned against.
First thing I did was write up a test program that looks something like this, to see what errors I would get:
int x = 42; int* px = &x; px++; *px = 12;
Compiled on GCC with -Wall. No warnings. I thought for sure some warning must prevent pointer arithmetic. After asking around I guess what I did above wasn't really pointer arithmetic, at least not in the compiler's eyes, so it's not warned against.