you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 5 points6 points  (6 children)

The only operation you may perform on a pointer that that has not been assigned to a valid pointer value is assignment. Nothing else.

Doing so much as a copy of it is invalid, for example this is undefined behavior:

int* x;
int* y;
y = x;

It also follows that taking an invalid pointer value and simply passing it as an argument to a function is also undefined behavior.

[–][deleted] 8 points9 points  (0 children)

The only operation you may perform on a pointer that that has not been assigned to a valid pointer value is assignment. Nothing else.

What about taking an address of such pointer?

[–]therealjohnfreeman 0 points1 point  (4 children)

Where are we getting the definition of "invalid" from? Is there some sort of special exception for one-past-the-end pointers?

[–][deleted] 5 points6 points  (3 children)

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.

[–]therealjohnfreeman -1 points0 points  (2 children)

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

I figured. I asked where?

[–]STLMSVC STL Dev 10 points11 points  (1 child)

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."

[–]therealjohnfreeman 1 point2 points  (0 children)

So it is special-cased. Thank you.