[Development] Upgrading the sources to C++11 keywords (Q_NULLPTR, etc.)

Matthew Woehlke mw_triad at users.sourceforge.net
Wed Feb 11 00:11:55 CET 2015

On 2015-02-10 17:44, André Pönitz wrote:
> On Tue, Feb 10, 2015 at 05:15:03PM -0500, Matthew Woehlke wrote:
>> On 2015-02-08 16:42, André Pönitz wrote:
>>> I.e. in case of a simple pointer initialization, why should one *ever* prefer 
>>> void something()
>>> {
>>>     Foo *f = Q_NULLPTR;
>>>     ...
>>> }
>>> over
>>> void something()
>>> {
>>>     Foo *f = 0;
>>>     ...
>>> }
>>> ?
>> For the same reason that *any* style rule exists: to encourage standard
>> practices that make it easier to use compiler tools to find bugs.
>> If I religiously use Q_NULLPTR, than I can also turn on the warning that
>> tells me when I use '0' as a null pointer constant. Which in turn can
>> help catch places where I really meant '0' and *not* a null pointer but
>> an unintended conversion is occurring. Conversely, because 'nullptr' is
>> not an integer, you can't accidentally call something that takes an
>> integer when you really meant a pointer (doesn't apply so much to your
>> specific example, but is a reason to use it in general).
>> If '0' is permitted in some contexts, then it is hard to use the
>> warning, and therefore hard to catch bugs. (And, as mentioned, not using
>> it *in headers* can be particularly annoying to someone who wants to
>> employ such a policy downstream, and can't because Qt produces huge
>> amounts of warning spam. Granted, "in headers" should perhaps read "in
>> public macros", but still...)
>> As Bo noted, it's your own problem whether or not to use it in Qt's own
>> .cpp files. Please consider your users when deciding whether or not to
>> use it in headers, however.
> Are you reading the mails you are responding to?


You asked why nullptr/Q_NULLPTR should be used in contexts where the
benefit is less obvious. I gave several reasons (here and also in a
different reply) why I think it should be - and indeed, why, when
possible, I personally *do* - use it everywhere, including places such
as the above example. I also noted that some of these reasons may or may
not be important to Qt.

(Admittedly some comments may be directed more to the direction of the
discussion in general than particular points of a specific mail. I image
most people prefer fewer mails :-).)

In what way do you feel that is off topic?


More information about the Development mailing list