dereferencing type-punned pointer will break strict-aliasing rules

Marcel Behlau marcel.behlau@elfin.de
Thu Jan 21 13:36:00 GMT 2016


Hi,

i wan't to create aliase (symbolic name and explizit type) for the 
elements of an char-array. Unfortunately my gcc produce the warning 
"dereferencing type-punned pointer will break strict-aliasing rules", if 
i use -O2 or bigger. Since i set -Werror, the warning will become an error.

I attached an example to this mail. To compile and generate the problem, 
i use "gcc -O2 -Werror -Wall main.cpp".

I found an workaround (without using pragma, or somethink else), with 
it's included in the code, too. To activate, pass an extra "-DWorking" 
to the gcc-Command. The workaround is working, but using an pointer is ugly.

Best regrads,

Marcel

-- 
Dipl. Ing (FH) Marcel Behlau
(Software Developer)

ELFIN GmbH
Siegburger Straße 215
50679 Köln
Germany

Tel: +49 (221) 6778932-0
Fax: +49 (221) 6778932-2
marcel.behlau@elfin.de
www.elfin.de


-------------- next part --------------
A non-text attachment was scrubbed...
Name: main.cpp
Type: text/x-c++src
Size: 341 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc-help/attachments/20160121/03cad177/attachment.bin>


More information about the Gcc-help mailing list