Re: [Lit.] Buffer overruns
From: glen herrmannsfeldt (gah_at_ugcs.caltech.edu)
Date: 02/03/05
- Next message: Jan Panteltje: "Re: My Wikipedia experiment, prime counting"
- Previous message: infobahn: "Re: [Lit.] Buffer overruns"
- In reply to: Phil Carmody: "Re: [Lit.] Buffer overruns"
- Next in thread: Phil Carmody: "Re: [Lit.] Buffer overruns"
- Reply: Phil Carmody: "Re: [Lit.] Buffer overruns"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
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
- Next message: Jan Panteltje: "Re: My Wikipedia experiment, prime counting"
- Previous message: infobahn: "Re: [Lit.] Buffer overruns"
- In reply to: Phil Carmody: "Re: [Lit.] Buffer overruns"
- Next in thread: Phil Carmody: "Re: [Lit.] Buffer overruns"
- Reply: Phil Carmody: "Re: [Lit.] Buffer overruns"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Relevant Pages
|