[Qt-interest] dereferencing pointer '<anonymous>' does break strict-aliasing rules error
Thiago Macieira
thiago at kde.org
Wed May 11 12:58:57 CEST 2011
On Wednesday, 11 de May de 2011 12:29:45 Konrad Rosenbaum wrote:
> On Tuesday 10 May 2011 14:38:23 mmiacca wrote:
> > While i try with Qt 2010.05 (Qt 4.7.0 32 bits Windows) to compile
> > C:\Qt\2010.05\qt\examples\qtestlib\tutorial4 i get this error
> > ..\..\..\include/QtTest/../../src/testlib/qtestspontaneevent.h:77:
> > warning: dereferencing pointer '<anonymous>' does break strict-aliasing
> > rules
>
> It's just a warning. Unless there is more (i.e. a real error) the
> application should still build and be executable.
That doesn't mean it will work right. Then again, there's warning-free code
that doesn't work right either :-)
The C and C++ languages forbid aliasing of types (except for aliasing with
char). So the following code is malformed:
int i = 42;
ushort u = (ushort *)&i;
u = 43;
printf("%d", i);
The types "i" and "u" alias each other and this is not allowed.
Undefined behaviour means anything could happen. The possible outcomes are
(assuming little-endian machine):
1) it prints "43" because it did modify the memory located by i.
2) it prints "42" because the compiler concludes that the variable i didn't
get modified between its assignment and its use. The two intermediary lines are
considered dead code and eliminated.
3) it calls your ex-mother-in-law and gives her your new girlfriend's phone
number.
--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
Senior Product Manager - Nokia, Qt Development Frameworks
PGP/GPG: 0x6EF45358; fingerprint:
E067 918B B660 DBD1 105C 966C 33F5 F005 6EF4 5358
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110511/4d2460b7/attachment.bin
More information about the Qt-interest-old
mailing list