Re: I met a "strange" thing...

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 10 December 2014 at 13:09, Jonathan Wakely wrote:
> On 10 December 2014 at 13:03, Graziano Servizi wrote:
>> Hi,
>>
>> by pure chance, during a copy+paste editing operation of a source code,
>> I ended up inadvertently with a code line like the following:
>>
>>                          int * x = int();
>>
>> Well, this code HAD BEEN COMPILED by g++ 4.8.3, and I cannot figure out its
>> meaning (from the compiler's point of view).
>
> int() creates an integer with value zero.
>
> In C++03 any integer expression with value zero is a valid null
> pointer value, so you can do any of these:
>
> int* p1 = 0;
> int* p2 = '\0';
> int* p3 = 1-1;

I should have said any integer *constant* expression.

The exact wording was:

"A null pointer constant is an integral constant expression (5.19)
prvalue of integer type that evaluates to zero or a prvalue of type
std::nullptr_t."

This was modified by
http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#903 so
that only integer literals are valid, so now int() and 1-1 are not
valid null pointer constants.




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux