Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid warnings about type-punned #32

Closed
wants to merge 2 commits into from

Conversation

markub3327
Copy link

Hello,

you used for estimating inverse square root old solution and modern compiler gives me warning:

/Users/martin/Documents/Arduino/libraries/Adafruit_AHRS/src/Adafruit_AHRS_Mahony.cpp: In static member function 'static float Adafruit_Mahony::invSqrt(float)':
/Users/martin/Documents/Arduino/libraries/Adafruit_AHRS/src/Adafruit_AHRS_Mahony.cpp:265:22: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
   long i = *(long *)&y;
                      ^
/Users/martin/Documents/Arduino/libraries/Adafruit_AHRS/src/Adafruit_AHRS_Mahony.cpp:267:18: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
   y = *(float *)&i;
                  ^
/Users/martin/Documents/Arduino/libraries/Adafruit_AHRS/src/Adafruit_AHRS_Madgwick.cpp: In static member function 'static float Adafruit_Madgwick::invSqrt(float)':
/Users/martin/Documents/Arduino/libraries/Adafruit_AHRS/src/Adafruit_AHRS_Madgwick.cpp:286:22: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
   long i = *(long *)&y;
                      ^
/Users/martin/Documents/Arduino/libraries/Adafruit_AHRS/src/Adafruit_AHRS_Madgwick.cpp:288:18: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
   y = *(float *)&i;
                  ^

The better way is using union as a trick. Thanks.

@tyeth
Copy link
Contributor

tyeth commented Nov 29, 2023

Thanks for your contribution @markub3327 ❤️
It's been effectively absorbed in #36 and released as 2.3.5

@tyeth tyeth closed this Nov 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants