simplefoc / Arduino-FOC

Arduino FOC for BLDC and Stepper motors - Arduino Based Field Oriented Control Algorithm Library
https://docs.simplefoc.com
MIT License
2.03k stars 521 forks source link

[BUG] Compiler warnings in foc_utils.cpp #296

Open jadoro opened 1 year ago

jadoro commented 1 year ago

When building SimpleFOC (with -Wall), I get the following compiler warnings – which unfortunately prevent a build with -Werror:

.pio/libdeps/nanoatmega328/Simple FOC/src/common/foc_utils.cpp: In function 'float _sqrtApprox(float)':
.pio/libdeps/nanoatmega328/Simple FOC/src/common/foc_utils.cpp:68:21: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
   i = * ( long * ) &y;
                     ^
.pio/libdeps/nanoatmega328/Simple FOC/src/common/foc_utils.cpp:70:22: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
   y = * ( float * ) &i;
                      ^

I'm using PlatformIO for building, with tool versions

framework-arduino-avr @ 5.1.0 
toolchain-atmelavr @ 1.70300.191015 (7.3.0)
Simple FOC @ 2.3.0

The responsible code section already links to Wikipedia, where alternative, more modern versions of that snippet can be found.