I would like to create macros for binary rotations.
My goal was to make those macros universal for both uint32_t
and uint64_t
operand types.
I came to this implementation:
#define ROTL(X, N) (((X) << (N)) | ((X) >> (8 * sizeof(X) - (N))))
#define ROTR(X, N) (((X) >> (N)) | ((X) << (8 * sizeof(X) - (N))))
Those macros work fine but gcc
compiler produces warnings during compilation:
warning: right shift count >= width of type [enabled by default]
#define ROTL(X, N) (((X) << (N)) | ((X) >> (8 * sizeof(X) - (N))))
warning: left shift count >= width of type [enabled by default]
#define ROTL(X, N) (((X) << (N)) | ((X) >> (8 * sizeof(X) - (N))))
I know that compiler is complaining about possible mismatch between type of X
and N
. But warnings are produced even when I cast both X
and N
:
ROTL((uint32_t)0xdeadbeef, (uint32_t)0U);
What can I do to get rid of these warning the proper way?