Quoting Pavel Heimlich <tropikhajma at gmail.com>:

> some comments from the Qt people:
>
> [23:56] <hajma> thiago_home: I think it might have been related to the use of
> -xalias_level CXX flag
> [23:56] <thiago_home> yes, compiler bug
> [23:56] <thiago_home> note how all 'this' pointers end in 9 or 1
> [23:56] <thiago_home> that's because QMutexLocker uses the lowest bit of the
> pointer to indicate whether it's locked or not
> [23:57] <thiago_home> but it turns them on and off properly. The compiler
> optimised out the check.
> [23:57] <thiago_home>                 val &= ~quintptr(1u);
> [23:57] <thiago_home>                 mtx->unlock();
> [23:57] <thiago_home> see? It's impossible to call mtx->unlock with a pointer
> that ends in 9 or 1
> [23:58] <thiago_home> (val and mtx are in a union)

Thiago is confusing implementation defined code that happens to work with GCC
and legal implementation independent C++.

From

http://gcc.gnu.org/bugs/#known

"
[type aliasing through incompatible pointers]

to fix the code above, you can use a union instead of a cast (note that this is
a GCC extension which might not work with other compilers):

#include <stdio.h>

int main()
{
  union
  {
    short a[2];
    int i;
  } u;

  u.a[0]=0x1111;
  u.a[1]=0x1111;

  u.i = 0x22222222;

  printf("%x %x\n", u.a[0], u.a[1]);
  return 0;
}
"

A+
Paul
-- 
Paul Floyd   http://paulf.free.fr

Reply via email to