[QUESTION] Usage of negative number notations on unsigned numbers.
Karthik B K
karthik.bk at incoresemi.com
Mon Nov 27 03:59:56 PST 2023
From: Andreas Schwab <schwab at linux-m68k.org>
Sent: Friday, November 24, 2023 4:38 PM
To: Karthik B K <karthik.bk at incoresemi.com>
Cc: opensbi at lists.infradead.org <opensbi at lists.infradead.org>
Subject: Re: [QUESTION] Usage of negative number notations on unsigned numbers.
On Nov 24 2023, Karthik B K wrote:
> If so, isn't it safer to use (~0UL) ? This could be a very silent bug. Please correct me if I'm wrong.
The safest way is to write -1 without any suffix. This is guaranteed to
evaluate to the maximum value when converted to any unsigned type.
This is with the assumption that the encoding for -1 == 2^32-1.
I'm still trying to understand what arithmetic negation mean to an unsigned quantity and its representation in UL.
While 0 has a defined encoding in a UL type, -1 does not!
karthik.
More information about the opensbi
mailing list