Bug 42711

Summary: the increment(++) or decrement(--) operators is wrong for short index of array
Product: gcc Reporter: Weiqiang Huo <aonebeam>
Component: cAssignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED DUPLICATE    
Severity: normal CC: alduc1, alexey, algorithmus, aonebeam, ashutosh.sharma.0204, asokumar, astier, av1474, bala, barnarr, behloul.younes, bmead15, buergel, calliari, carpman, chuchunxin, devnull, d_picco, edulix, eric.mcvicker, fuchsia.groan, gaurav_har, gcc-bugs, gcc, ggs, gjasny, j.witteveen, jandres, janis, jesser, jompo, krs, lid, lindahlb, lxg8906, mayer, mikaldaz, mike.clarkson, nakkore, nanericwang, nobs, pierre.van.de.laar_at_philips.com, qyang, ramiller, raoulgough, raphael.ribas, rglan, rjvbertin, robc, s9322036, SimonX200, smartmouse714, super.aorta, svetozarmarkov, tczarnecki, terrix, tim.bruylants, vanveghel, vitaly, windows2000d, zshao
Priority: P3    
Version: unknown   
Target Milestone: ---   
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed:
Attachments: The source of wrong result of decrement, increment is the same

Description Weiqiang Huo 2010-01-12 16:11:34 UTC
The following tests are made on solaris 5.10 platform.
This is the example of the decrement(--) for short index of array:
/*********************************************************/
#include <stdio.h>
int main()
{
	int 				aryHuowq[3] = {0};
	short 				nIndex = 2; /* nIndex is short */

	aryHuowq[nIndex--] = nIndex + 1;
	printf("array[%d] : %d\n", nIndex+1, aryHuowq[nIndex+1]);
	return 0;
}
/*****************************************************************/
/* The result is "array[2] : 2", but it should be "array[2] : 3" */
/*****************************************************************/

If nIndex is type of int, then the result is "array[2] : 3".
Comment 1 Weiqiang Huo 2010-01-12 16:14:46 UTC
Created attachment 19559 [details]
The source of wrong result of decrement, increment is the same

The result is wrong.
Comment 2 Andreas Schwab 2010-01-12 16:24:19 UTC

*** This bug has been marked as a duplicate of 11751 ***