Re: [Lit.] Buffer overruns

From: glen herrmannsfeldt (gah_at_ugcs.caltech.edu)
Date: 02/03/05


Date: Thu, 03 Feb 2005 10:27:05 -0800

Phil Carmody wrote:

(snip)

> Left bitshifts of signeds are only UB if they would overflow.

> In such situations there's no obvious correct answer anyway (scaling
> should never alter sign), and so it's not just UB in the C standard,
> it's intrinsically meaningless code. If you (not _you_ "you", generic
> "you") can't tell signed from unsigned - stop programming now!

C allows twos complement, ones complement and sign magnitude.
I believe that shifts on those can generate numerically
different results, even when they don't overflow.

As I understand it, there is at least one ones complement
machine still in production. I don't know of any fixed point
sign magnitude machines, though.

> Right bitshifts of signeds are never intrinsically UB.
> (i.e. you could embed UB into such an expression, but it wouldn't
> be the shifting that was the UB).

> Are you confusing UB with "implementation-defined behaviour"?

That does happen, but in either case you can't depend on the result.

-- glen



Relevant Pages

  • Re: random_number
    ... 36 bits was "the standard" at one point in history. ... Some machines even used sign magnitude (twos complement in other jargons) for symmetric ranges. ...
    (comp.lang.fortran)
  • Re: So what Standard are we working off?
    ... enforced to 2s complement. ... the standard can be implemented on architectures that don't use ... test should I use to eliminate all other number representation systems? ... Do you also use C99 compilers on those platforms every ...
    (comp.lang.c)
  • Re: So what Standard are we working off?
    ... enforced to 2s complement. ... the standard can be implemented on architectures that don't use ... test should I use to eliminate all other number representation systems? ... Do you also use C99 compilers on those platforms every ...
    (comp.lang.c)
  • Re: code portability
    ... It is true that the additive inverse is not required to be distinct ... The C operations on the unsigned integral types are strictly defined; ... That the *C standard* has these ... And I'm sure there are 1s complement ...
    (comp.lang.c)
  • Re: So what Standard are we working off?
    ... enforced to 2s complement. ... the standard can be implemented on architectures that don't use ... *I* as a programmer can will never ever be in a position to test the ... Do you also use C99 compilers on those platforms every ...
    (comp.lang.c)

Quantcast