[Development] Qt 5.2 header diff: QtXmlPatterns

Thiago Macieira thiago.macieira at intel.com
Tue Nov 5 17:55:22 CET 2013


On terça-feira, 5 de novembro de 2013 12:24:32, Marc Mutz wrote:
> On Tuesday, November 05, 2013 01:07:32 Thiago Macieira wrote:
> > -            return (void *)qptrdiff(data);
> > +            char *null = 0;
> > +            return null + qptrdiff(data);
> 
> Since this is equivalent to
> 
>     return 0[qptrdiff(data)];
> 
> isn't that dereferencing the nullptr and therefore undefined behaviour?

No. This is equivalent to:

	return &0[qptrdiff(data)];

There's no dereferencing.

Adding/subtracting null is a good way to make pointer-to-integer conversions 
without casts.

> What's wrong with
> 
>    reinterpret_cast<void*>(qptrdiff(data));

Nothing, but it's uglier since it has a cast.
 
> Or simply
> 
>   return ptr;
> 
> which forms a union with `data`?

Now that's undefined behaviour under C++98 (accessing a union member that was 
not the last one you set).

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.qt-project.org/pipermail/development/attachments/20131105/1e7b76b3/attachment.sig>


More information about the Development mailing list