Why do shift operators undergo integral promotion?

Jonathan M Davis jmdavisProg at gmx.com
Tue Aug 9 15:04:40 PDT 2011


> On 8/9/2011 2:08 PM, Jonathan M Davis wrote:
> > From what I can see though, it sure looks like any C code which relies on
> > the C behavior would be buggy.
> 
> I don't see any way to make that judgment. It's been Standard C behavior
> forever, including K+R prehistory. It's guaranteed that a lot of code will
> rely on it, whether or not anyone considers it good form.

Hmmm. It seems to me that the question is whether anyone would ever 
_intentially_ use this behavior. Is there any benefit to it whatsoever? If 
not, I'd argue that the risk of breakage to C code being ported over is 
minimal and that the behavior should be fixed in D. Now, if there _is_ a 
benefit to it such that someone would use it intentionally, then that's 
another story, but it sure likes like the only reason that it would occur in C 
code would be because the programmer who wrote it screwed up.

Now, that's still going to change the behavior of any code which used this 
behavior - even if it was by accident - which risks making code fail to work 
even if it only worked through a miracle before (i.e. in spite of the bug). 
So, maybe that's enough that we can't fix it. But it sure seems like the risk 
of new breakage is very low, since code whose behavior would change was broken 
in the first place, and I'd hate to see D's behavior stay like this if we can 
fix it.

- Jonathan M Davis


More information about the Digitalmars-d mailing list