🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: mod.computers.gould
1 messages
1 total messages Started by Larry Parmelee Fri, 22 Nov 1985 14:59
cc bug with short unsigned constants
#8
Author: Larry Parmelee
Date: Fri, 22 Nov 1985 14:59
50 lines
1795 bytes
Index:	/usr/src/lib/ccom

Description:
	Unsigned short integer constants sometimes get sign extension, 
	when this is not desired.

Repeat-By:
	Compile the following little program, and run it.
	
------cut here------
main()
{
    int i, ij1, ij2;
    unsigned short int j;
 	
    i = 10;
    j = (unsigned short)(01<<15);

    ij1 = i + j ;				/* Line 9 */
    ij2 = i + (unsigned short)(01<<15) ; 	/* Line 10-- BUG!!! */

    printf("i=0x%x, j=0x%x,  ij1=0x%x,  ij2=0x%x \n",i,j,ij1,ij2);
}
------cut here------

	The output from the above is:

i=0xa, j=0x8000,  ij1=0x800a,  ij2=0xffff800a
	
	Line 9 produces the following code:  (No Bug)

--	line 9, file "main.c"
	movh	11w+LOC1[b2],r0
	andw	#0xffff,r0
	addw	8w+LOC1[b2],r0
	movw	r0,9w+LOC1[b2]

	Line 10 produces this--(BUG!!!: Note the missing "andw")

--	line 10, file "main.c"
	movh	#0x8000,r0
	addw	8w+LOC1[b2],r0
	movw	r0,10w+LOC1[b2]

	The operation (in the above, addition) does not seem to be significant;
	The same problem occurs with "or".

	-Larry Parmelee
	parmelee@gvax.cs.cornell.edu
	{allegra,ihnp4,decvax}!cornell!parmelee
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads