1

I am using AVR32 Studio studio to compile my code for AVRUC3 controller. When I switched to Optimization level -O2(optimization more) ,this pointer warnings " dereferncing type-punned pointer will break strict aliasing rules " started to appear. I know why I am getting this warnings...

But My question is Should I run my code with -O2 and solve this all errors OR is it OK enough to continue having them and compile with -O0(No optimization).

E_net4
  • 27,810
  • 13
  • 101
  • 139
  • 5
    yes, you should fix these errors as they result in UB. – The Paramagnetic Croissant Nov 12 '15 at 16:50
  • 2
    gcc strict aliasing warnings are [subject to false negatives/positives](http://stackoverflow.com/a/25118277/1708801) and can be effected by optimization level etc... just because the warning goes away does not mean it is not undefined behavior. – Shafik Yaghmour Nov 12 '15 at 16:50
  • It would help to see an example of a type punned pointer that the compiler is complaining about. Windows API uses a lot of [type punning](http://en.wikipedia.org/wiki/Type_punning#Use_of_union) in structures, usually via unions, and it's not an issue there. – rcgldr Nov 12 '15 at 18:10
  • @rcgldr yes but [gcc explicitly supports type punning via a union](http://stackoverflow.com/a/31080901/1708801) even using strict-aliasing. Although I agree an example of the code would be helpful. – Shafik Yaghmour Nov 12 '15 at 18:18
  • Thanks for the help everyone – Nirmal Panchal Nov 16 '15 at 17:06

0 Answers0