User account creation filtered due to spam.

Bug 42711 - the increment(++) or decrement(--) operators is wrong for short index of array
Summary: the increment(++) or decrement(--) operators is wrong for short index of array
Status: RESOLVED DUPLICATE of bug 11751
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: unknown
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-01-12 16:11 UTC by Weiqiang Huo
Modified: 2010-01-12 16:24 UTC (History)
61 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
The source of wrong result of decrement, increment is the same (155 bytes, text/plain)
2010-01-12 16:14 UTC, Weiqiang Huo
Details

Note You need to log in before you can comment on or make changes to this bug.
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 ***