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

9

u/KrzaQ2 dev Jan 21 '13

I wasn't aware that creation of a pointer without assigning a value to it is a UB.

6

u/[deleted] Jan 21 '13

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.

8

u/[deleted] Jan 21 '13

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?