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
C objects
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
Reply to thread
Message
[QUOTE="Joe Wright, post: 2384030"] I have not snipped anything from Chuck's post. I fear we are wandering off point if not off topic. In no particular order I offer various considerations for the null pointer value being zero. 1. It is useful to have functions return an error indication if the function fails. Consider malloc(). It returns the address of allocated memory if it succeeds. What shall we have it do if there is no memory available? Return a value which cannot be a valid address. 2. Given an address, perhaps stored in a pointer, how might we examine it to determine its validity? Sadly, we can't. C programmers see pointer values as unsigned integers with no upper bound. So, if we need a single pointer value within the domains of unsigned integers of various widths, we are limited to the lower bound, 0. This is not a bad choice. Usually 0 is an important address to the underlying OS and we shouldn't write to it in any case. Reserving address 0 for our NULL pointer constant is perfect. We are warned that writing or even reading address zero might cause your house to burn down, and so we don't do it. Tell me why any C implementation would have a null pointer other than zero? So that writing through NULL might be safer? Nonsense. Writing through NULL is the ultimate sin. So why? [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
C Programming
C objects
Top