bug in v7 C compiler

utzoo!decvax!ucbvax!naha at LL-ASG utzoo!decvax!ucbvax!naha at LL-ASG
Fri Jul 31 12:30:57 AEST 1981


From: naha at LL-ASG (Mark Nahabedian)
The version 7 C compiler causes sign extension to be performed when one casts
an unsigned integer to a long when innitializing variables.

As a test, consider the source program 

long a = (long) 0177777;
long b = (long) (unsigned int) 0177777;
long c = 0177777L;
long x;
int y = 0177777;
unsigned int z = 0177777;
foo()
{
x = (long) y;
x = (long) z;
}

which produces the assembler input

 .globl	_a
 .data
_a:
177777; 177777
 .globl	_b
 .data
_b:
177777; 177777
 .globl	_c
 .data
_c:
0; 177777
 .comm	_x,4
 .globl	_y
 .data
_y:
177777
 .globl	_z
 .data
_z:
177777
 .globl	_foo
 .text
_foo:
~~foo:
jsr	r5,csv
jbr	L1
L2:mov	_y,2+_x
sxt	_x
mov	_z,2+_x
clr	_x
L3:jmp	cret
L1:jbr	L2
 .globl
 .data

Note that in the case of actual assingmet at run-time it sign extends when
it should and doesn't when it shouldn't. 

When it innitializes the variable b, it converts -1 integer to -1 long even
when it has been explicitly told that the -1 integer is really an unsigned
0177777 integer.

Any ideas about why it does this or how it could be fixed?


-----





More information about the Comp.unix.wizards mailing list