by 2bitencryption · 10y ago · 0 comments
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.
http://stackoverflow.com/questions/11714827/how-to-turn-on-l...
In C++, directly using pointers to access arrays is often discouraged, in favour of using the standard collection types and their associated iterator types. So in code that follows this style, it is possible to warn about uses of pointer arithmetic, and the core C++ guidelines do suggest such a warning. But the guidelines also point out that "this rule would generate a huge number of false positives if applied to an older code base": https://github.com/isocpp/CppCoreGuidelines/blob/master/CppC...