dereferencing type-punned pointer will break strict-aliasing rules

Marcel Behlau
Thu Jan 21 13:36:00 GMT 2016


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,


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

Siegburger Straße 215
50679 Köln

Tel: +49 (221) 6778932-0
Fax: +49 (221) 6778932-2

-------------- next part --------------
A non-text attachment was scrubbed...
Name: main.cpp
Type: text/x-c++src
Size: 341 bytes
Desc: not available
URL: <>

More information about the Gcc-help mailing list