3 ms·
So thats what I initially thought but then I ran it and it works so IDK anything anymore.
by rhodysurf 6y ago
So thats what I initially thought but then I ran it and it works so IDK anything anymore.
- steveklabnik 6y agoUB can do anything, including something that seems like it works. Just because the memory has been deallocated doesn't mean that the bytes there were changed. The pointer may still point to them, and it may still "work."
- mlindner 6y agoIt's undefined behavior, so it'll literally print anything. On my system with my compiler version it'll print xyz without any optimization, but if I use -O3 optimization it prints nothing. But it could just as easily segfault or print garbage from memory. Edit: If I move the first line into a function and return that string_view, then with optimizations it still prints nothing, but without optimizations it prints random varying garbage each time I run it, different each time.