[QUESTION] Usage of negative number notations on unsigned numbers.
iamkarthikbk opened this issue · 1 comments
iamkarthikbk commented
Hi. The pmp_get function in lib/sbi/riscv_asm.c uses a negative number notation on an unsigned integer.
pmpaddr = -1UL;
Just curious why it is this way. I believe that the intention here is to represent the largest unsigned long number.
If so, isn't it safer to use (~0UL) ? This could be a very silent bug. Please correct me if I'm wrong.
SiFiveHolland commented
Both are equivalent (assuming two's complement), though -1UL is more idiomatic. It's not really "negative number notation", but the unary minus operator, which is still well-defined for unsigned integers.