Sujet : Re: question about nullptr
De : jameskuyper (at) *nospam* alumni.caltech.edu (James Kuyper)
Groupes : comp.lang.cDate : 07. Jul 2024, 02:44:03
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v6crt3$1gpa$2@dont-email.me>
References : 1 2 3 4 5
User-Agent : Mozilla Thunderbird
On 7/6/24 4:23 PM, Chris M. Thomasson wrote:
On 7/6/2024 7:04 AM, Scott Lurndal wrote:
...
Whereas I spent 6 years programming on an architecture[*] where a
null pointer was represented in hardware by the value 0xc0eeeeee. I
always
use the NULL macro in both C and C++ code.
Where:
void* x = 0;
Should be x = 0xc0eeeeee, right?
No, 0 is a null pointer constant. The C standard requires that when a
null pointer constant is converted to a pointer value, it must be
converted to a null pointer of that type. The result will be that the
representation of 'x' after such an assignment would be 0xc0eeeeee.
Whether or not an integer value of 0xc0eeeeee can be converted to a
pointer type, and what that pointer's value would be after the
conversion is up to the implementation.
Note that even after x acquires that representation, it's still required
to compare equal to 0. For the purposes of the comparison, the null
pointer constant gets converted to a null pointer of the appropriate
type. All null pointers, regardless of representation (the C standard
allows there to be multiple ways of representing null pointers) must
compare equal.