In the book "C++ Primer, 5th ed", section 2.4.4, the entire section explains about "constexpr". Then an exercise as below is given in the book:
Exercise 2.32: Is the following code legal or not? If not, how might you make it legal?
int null = 0, *p = null;
I understand that a quick way to fix it is to just change it to *p = nullptr, or NULL, or use reinterpret_cast. But I think the book's intention is to use something related to constexpr. So my question is, how would the above exercise be solved properly? (I think the book's intention is to init the value of p to 0, not the address of null.)
I made below trials but both failed at compilation:
trial 1, adding constexpr:
constexpr int null = 0;
int *p = null;
trial 2, adding const;
const int null = 0;
int *p = null;
(I made this trial based on the wordings in book chapter 4.11.2, Other implicit conversions: "A constant integral value of 0 and the literal nullptr can be converted to any pointer type;")
Thank you in advance. (Reason being asked as a new question: this is asked as a new question in hope of finding a solution. there is another closely related question but no proposed solution was given Is this constexpr integer not a null pointer constant?)