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

Allan Sandfeld Jensen kde at carewolf.com
Mon Feb 9 00:07:15 CET 2015


On Sunday 08 February 2015, André Pönitz wrote:
> On Sun, Feb 08, 2015 at 10:17:40PM +0100, Allan Sandfeld Jensen wrote:
> > What would be the point of macros if they always expanded? The entire
> > point and usefulness of these macros is that they expand to standard
> > keywords when those standard keywords exists.
> 
> What's the point of using a macro in circumstances where a portable,
> standard conforming, safe-to-use, shorter-to-type, version _without_ using
> a macro exists?
> 
> 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 sake of keeping this part of the discussion simple, I specifically
> mean 'Q_NULLPTR, the macro', _not_ 'nullptr', and I specifically mean the
> context of initializing a local pointer variable. So: Any advantage? Any
> advantage outweighing the disadvantages?
> 
If you use in the wrongly in a function call where integers are supposed to be 
used, we will get an error on the C++11 enabled builds even it if passes on 
C++98. Could also expose wrong implied constructors being used.

I am not a big fan of nullptr, but it makes sense in a few places, and can see 
the point in use Q_NULLPTR there.

`Allan



More information about the Development mailing list