Liste des Groupes | Revenir à cl c |
James Kuyper <jameskuyper@alumni.caltech.edu> writes:void* x = (void*)(0xc0eeeeee); // aka NULLOn 7/6/24 4:23 PM, Chris M. Thomasson wrote:Furthermore, `void* x = 0xc0eeeeee;` is a constraint violation. ThereOn 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.
is no implicit conversion from integers to pointers other than the
special case of a null pointer constant, which 0xc0eeeeee is not.
Les messages affichés proviennent d'usenet.