[Libclc-dev] [PATCH] integer: Update integer limits to comply with spec

Pflanzer, Moritz via Libclc-dev libclc-dev at lists.llvm.org
Thu Sep 10 10:22:16 PDT 2015


> Is there some reason why
> 
> #define INT_MIN ((int)-2147483648)
> 
> won't work?

This seems to work, at least no error is generated, but I guess it produces an signed overflow. The '-' is treated as unary operator and not as part of the number. Therefore first '2147483648' is evaluated but is to large for signed int (and is therefore treated as long without the explicit cast). Afterwards the number would be negated. (See http://lists.llvm.org/pipermail/llvm-dev/2015-September/090279.html)

> I also don't understand how subtracting one guarantees the result will
> be an integer and not long.

The number 2147483647 is still valid for signed int and thus no conversion to long is implicitly performed. Afterwards it is negated and one is subtracted which leads to the correct value for INT_MIN without an overflow.

Moritz


More information about the Libclc-dev mailing list