Out of curiosity, I tried to rewrite that code to make it more readable. At least in clang, all the variants become equivalent at -O3: https://godbolt.org/z/6q49sY
And I know that the union trick is UB, but the major compilers accept it anyway.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I am using Cppcheck 2.1 and I get an error indicating 'the address of location variable "checksum" is accessed at non-zero index'.
Here is the code:
This looks like a false positive to me?!
Last edit: Tom 2020-09-14
I can reproduce this with v2.3 and head.
I have created a ticket: https://trac.cppcheck.net/ticket/10156
Out of curiosity, I tried to rewrite that code to make it more readable. At least in clang, all the variants become equivalent at -O3: https://godbolt.org/z/6q49sY
And I know that the union trick is UB, but the major compilers accept it anyway.