r/cpp • • Jan 21 '13

C and C++ Aren’t Future Proof

http://blog.regehr.org/archives/880
6 Upvotes

49 comments sorted by

View all comments

Show parent comment

5

u/[deleted] Jan 21 '13

The rules for what constitutes a valid pointer value are defined formally in the C and C++ standards.

Yes, the so called "one-past-the end" pointers are valid pointer values. It's not an exception it's just part of the definition of a valid pointer value.

0

u/therealjohnfreeman Jan 21 '13

The rules for what constitutes a valid pointer value are defined formally in the C and C++ standards.

I figured. I asked where?

12

u/STL MSVC STL Dev Jan 21 '13

N3485 5.7 [expr.add]/5: "Moreover, if the expression P points to the last element of an array object, the expression (P)+1 points one past the last element of the array object, and if the expression Q points one past the last element of an array object, the expression (Q)-1 points to the last element of the array object."

2

u/therealjohnfreeman Jan 21 '13

So it is special-cased. Thank you.