Can using 0L to initialize a pointer in C++ cause problems?

sharptooth picture sharptooth · Dec 15, 2009 · Viewed 12.1k times · Source

In this question an initializer is used to set a pointer to null. Instead of using value of 0 value of 0L is used. I've read that one should use exactly 0 for null pointers because exact null pointer representation is implementation-specific.

Can using 0L to set a pointer to null cause problems while porting?

Answer

Andreas Brinck picture Andreas Brinck · Dec 15, 2009

From the standard (4.10.1):

A null pointer constant is an integral constant expression (5.19) rvalue of integer type that evaluates to zero

so I guess 0L is ok.