Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
C Programming
How to know the memory pointed by a ptr is freed?
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
Reply to thread
Message
[QUOTE="Keith Thompson, post: 2384129"] or unsigned char foo[sizeof ptr]; /* no assumption necessary */ The UB happens when the value of ptr is evaluated *as a pointer*. Taking its address with "&ptr" is ok because it just gives you the address of an object you own, without reference to its value. Computing its size with "sizeof ptr" doesn't evaluate anything; it just tells you how big the object is (something that can be done at compilation time). This information is passed to memcpy(), which just deals with bytes, not with pointers. And now for something completely different: a Monty Python explanation of invalid pointers. The infamous Killer Joke was a joke so funny that anyone hearing it would immediately die of laughter. The Allies worked to translate it into German so they could use it as a weapon. Each translator worked on only one word of the joke (one translator who accidentally saw two consecutive words spent several weeks in hospital). Each individual word of the Killer Joke is harmless. Only the entire joke is deadly. An invalid pointer is the Killer Joke, deadly to anyone who reads it. The individual bytes composing the pointer are the words of the joke, harmless in themselves. The gentlemen of Monty Python are, of course, masters of Undefined Behavior. [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
C Programming
How to know the memory pointed by a ptr is freed?
Top