MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/cpp/comments/16ysbr/c_and_c_arent_future_proof/c80uokf/?context=3
r/cpp • u/last_useful_man • Jan 21 '13
49 comments sorted by
View all comments
9
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?
6
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?
8
What about taking an address of such pointer?
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.