[comp.lang.c] Code generation bug in Microsoft C 5.1

franke@rwthinf.UUCP (Christian Franke) (08/09/88)

Code generation bug in Microsoft C 5.1 (MS-DOS, OS/2)
======================================

If an unsigned char variable is {pre|post}incremented inside an array subscript,
the compiler generates code to increment a *word*. The error does not
occur if the variable is signed.

Example

	char c;
	unsigned char uc;
	char a[10];

	error()
	{
	    char i;
		i = uc++;    /* OK */
		i = a[c++];  /* OK */
		i = a[uc++]; /* Error */
	}

Code generated

	;****** i = a[uc++];
		mov bl,BYTE PTR _uc
		inc WORD PTR _uc	*WOW*
		sub bh,bh
		mov al,BYTE PTR _a[bx]
		mov BYTE PTR [bp-2],al


This error does not occur with MSC version 4.0.


Christian Franke

	Aachen University of Technology
	Lehrstuhl fuer Informatik I
	Ahornstrasse 55
	D-5100 Aachen
	Federal Republic of Germany
	Tel.: 0241 / 80-3586

	UUCP: franke@rwthinf.uucp ({...mcvax}!unido!rwthinf!franke)