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
Null pointers
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
Reply to thread
Message
[QUOTE="Christian Bau, post: 2382391"] How do you do that comparison? Let's say you write char* p = malloc (100); and the call succeeds. "p == NULL" and "p == 0" will both be false. However, it can be true that all the bits in p are zero on this implementation. If you write int i = 0; char* q = (char *) i; then the C99 Standard guarantees that q is a null pointer. On this implementation it means q will point to address 0x12345678 and it will not be equal to p. Unlike most current compilers, a compiler for this implementation will have to produce real code to cast from int to char*. If int and char* have the same size and alignment, then you could try to write * (int *) &q = 0; to set q to a null pointer. This will work on many implementations but not on this one; it is indeed undefined behavior. [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
C Programming
Null pointers
Top