[comp.windows.x] right shifting negative numbers considered harmful

andy@nthropy.UUCP (Andy Lowe) (01/24/91)

Dear X server hackers,

My copy of the ANSI C spec says that when right shifting E1 >> E2, "If
E1 has a signed type, whether the right shift is logical (fill with
zeros) or arithmetic (fill with a copy of the sign bit) is
implementation-defined." (section 3.3.7)

Consider the following fragment of code from the MIARCOCTANTSHIFT macro
in mizerarc.h  

...
	    d = b - (a >> 1) - d + (k3 >> 3); \
...

this is called out from the cfb arc drawing routines.  Note that
variable a can be negative.

I have the misfortune to be running on an architecture without an
arithmetic right shift instruction, and so my compiler has exercised
it's "implementation-defined" option.  

In the interests of portability, can someone arrange to fix this
apparent ANSI non-compliance in the standard distribution?  I'm using
R4.  Perhaps it is already fixed in R5.  Does anybody know?

many thanks.

Andy Lowe
andy@nth.com

Nagesh_Pabbisetty.Henr801C@xerox.COM (01/24/91)

I am glad(?) to see that I am not the only one who feels that way. I got bitten
by this in the arc drawing code. It took us quite a while to locate and change
it.

- nagesh (pabbiset@arisia.xerox.com)
-------------------------------------------------------------------------------
Intelnet: 8*227-5458				MaBell: (716)427-5458
XNS	: pabbisetty:henr801c:xerox		Snail Mail:
Arpa	: pabbiset@arisia.xerox.com		  1350 Jefferson Road, 801-27C,
						  Rochester, NY 14623.
-------------------------------------------------------------------------------

Nagesh_Pabbisetty.Henr801C@xerox.COM (01/24/91)

      Dear X server hackers,
      
      My copy of the ANSI C spec says that when right shifting E1 >> E2, "If
      E1 has a signed type, whether the right shift is logical (fill with
      zeros) or arithmetic (fill with a copy of the sign bit) is
      implementation-defined." (section 3.3.7)
      
      Consider the following fragment of code from the MIARCOCTANTSHIFT macro
      in mizerarc.h  
      
      ...
		  d = b - (a >> 1) - d + (k3 >> 3); \
      ...
      
      this is called out from the cfb arc drawing routines.  Note that
      variable a can be negative.
      
      I have the misfortune to be running on an architecture without an
      arithmetic right shift instruction, and so my compiler has exercised
      it's "implementation-defined" option.  
      
      In the interests of portability, can someone arrange to fix this
      apparent ANSI non-compliance in the standard distribution?  I'm using
      R4.  Perhaps it is already fixed in R5.  Does anybody know?
      
      many thanks.
      
      Andy Lowe
      andy@nth.com


I am glad(;-) to see that I am not the only one who feels that way. 
I got bitten by this in the arc drawing code. 
It took us quite a while to locate and change right shifts to divides (:-(


- nagesh (pabbiset@arisia.xerox.com)
-------------------------------------------------------------------------------
Intelnet: 8*227-5458				MaBell: (716)427-5458
XNS	: pabbisetty:henr801c:xerox		Snail Mail:
Arpa	: pabbiset@arisia.xerox.com		  1350 Jefferson Road, 801-27C, 
						  Rochester, NY 14623.
-------------------------------------------------------------------------------