Re: [petsc-dev] technical C question
On Thu, Apr 7, 2016 at 2:28 PM, Barry Smith <[email protected]> wrote:
We have code
return (BT_idx = index/PETSC_BITS_PER_BYTE, BT_c = array[BT_idx], BT_mask = (char)(1 << index%PETSC_BITS_PER_BYTE), array[BT_idx] = (char)(BT_c | BT_mask), (char)(BT_c & BT_mask));
inside
petscbt.h
the clang static code analyzer reports
In file included from /sandbox/petsc/petsc.clone/include/petsc/private/matimpl.h:1233: /sandbox/petsc/petsc.clone/include/petscbt.h:85:36: warning: The result of the '<<' expression is undefined BT_mask = (char)(1 << index%PETSC_BITS_PER_BYTE), ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
Is the code wrong/unnecessary or clang?
It looks right to me: index%PETSC_BITS_PER_BYTE gives the offset of this bit in the current byte. 1 << index%PETSC_BITS_PER_BYTE Gives an int with a 1 at the offset'th bit, and then we cast to a char. I have no idea why clang complains. Matt
Thanks
-- What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead. -- Norbert Wiener
participants (1)
-
Matthew Knepley