News for hackers. Stuff that matters.
Re:C++ Annotations by cjensen on Monday November 26, 2018 @12:36PM (#18535117)
First, that's inherently non-portable. That aside...

On most systems, the null pointer happens to be a pointer to address zero. For other systems, e.g. 8086 16-bit mode, you can create a intptr_t (which is the same size as a pointer) and set it to zero. Then cast it to a pointer. Such casting is always done bitwise, so it will work.

The compiler knows to turn the following into the null pointer

  void *p = (void *) 0;
but the compiler will NOT turn the following into a null pointer

  void *p = (void *) (uintptr_t) 0;
because the literal 0 is now in an integer context, not a pointer context.
Re:C++ Annotations by Koshkin on Monday November 26, 2018 @05:19PM (#18537358)
BTW 0 is a valid literal value of a pointer type (so you do not need a cast).
Re:C++ Annotations by guipsp on Wednesday November 28, 2018 @03:33AM (#18550067)
Thank you!