Using nullptr instead of Q_NULLPTR

Jarosław Staniek staniek at kde.org
Fri Aug 14 22:53:44 BST 2015


Thiago Macieira wrote:

> On Friday 14 August 2015 14:34:49 Jarosław Staniek wrote:
>> I also think we agree that anything other than 0 is good for readability
>> and  readability should be the priority.
> 
> Note that the Qt 5.7 policy still allows and even asks for use of 0 as
> null in some places. The policy is:
> 
>  * always use nullptr in public headers. No exceptions.
>  * use nullptr or 0 in non-public headers or regular sources so
>  readability is
>    good. There's no point in using nullptr where 0 is obviously a null
>    pointer, like:
> char *s = 0;
> 
>> Then, there's the consistency factor -- a reason to cover the topic of
>> null pointers in the guide. I find neither Qt is consistent in what to
>> use, Qt is not an example here then.
> 
> The policy above applies to Qt 5.7. For 5.6, only the first part applies
> and it needs to be Q_NULLPTR.
> 
>> In the worst case if someone calls us too modern, e.g for embedded
>> projects,  we'd be able a macro to ECM kdecompilersettings that defined
>> nullptr back to 0 (or is this already supported by cmake/etc.?)
> 
> Don't do that. If you use nullptr, there's no going back to zero because
> it's not the same. You've irrevocably locked yourself into requiring a
> compiler that supports it.

I should say "back to Q_NULLPTR", right? 

It's just helping people with old compilers by making the code SC.
 
>> PS: A Krazy check checking for usage of NULLs and Q_NULLPTR would be
>> lovely.  Checking the use of 0's isn't easy, right?
> 
> -Wzero-as-null-pointer-constant
> 
> Qt headers should pass that starting with 5.6.

Yes it's useful for KF5. @everyone: can we have have it added in our build 
flags for KF5 (maybe not for users of KF5)?


-- 
regards, Jaroslaw Staniek

KDE:
: A world-wide network of software engineers, artists, writers, translators
: and facilitators committed to Free Software development - http://kde.org
Calligra Suite:
: A graphic art and office suite - http://calligra.org
Kexi:
: A visual database apps builder - http://calligra.org/kexi
Qt Certified Specialist:
: http://www.linkedin.com/in/jstaniek





More information about the kde-core-devel mailing list