You might want to consider forcing 64 bit math. According to "C" standard, result of shifting of a variable with N bits is only defined when the number of shifts is less than the size of the variable (0..N-1)
Performing the shift on (~0) (integer, usually 32 bit), will result in undefined behavior for ~n+33 (n=0) since ~n+33 = 32, above the limit of 31.
Changing the code to use (~0L) produce the requested result masking(0) = 0
Assuming that you run on generic Linux - gcc will default to 32 bit integer, 64 bit long and 64 bit pointer.
include <stdio.h>
int masking(int n) {
return (~0UL)<<(~n+33);
}
void main(void)
{
for (int i=0 ; i<4 ; i++) {
printf("M(%d)=%x\n", i, masking(i)) ;
}
}
Output:
M(0)=0
M(1)=80000000
M(2)=c0000000
M(3)=e0000000