On Fri, 25 Nov 2016, Torbjörn Granlund wrote:

Marc Glisse <marc.gli...@inria.fr> writes:

 Surprisingly, shifting negative numbers left is undefined, while
 shifting them right it implementation-defined.

I fail to appreciate the difference between these definitions of
undefinedness.

I assume "undefined" means that the computer will not explode, or even
cause any less dramatic security issues, or even terminate execution.
It's undefined only in that the result can be any bit pattern.  This bit
pattern might vary bewteen any two computers, with used compiler and
between two executions.

Actually, yes, "undefined behavior" means that the computer can explode, execution can be terminated (what happens with the sanitizer), etc.

And "implementation-defined" means that the bit pattern can be anything,
varying between computers (or compiler on one computer).

"Implementation-defined value" means that every compiler must return a value, and document what that value is (in practice, arithmetic shift).

--
Marc Glisse
_______________________________________________
gmp-devel mailing list
gmp-devel@gmplib.org
https://gmplib.org/mailman/listinfo/gmp-devel

Reply via email to