User account creation filtered due to spam.

Bug 16309 - different behavior in lvalue assignment in -O0 & -O2
Summary: different behavior in lvalue assignment in -O0 & -O2
Status: RESOLVED DUPLICATE of bug 11751
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 3.3.3
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
Depends on:
Reported: 2004-07-01 08:49 UTC by Giorgio Alfarano
Modified: 2005-07-23 22:49 UTC (History)
1 user (show)

See Also:
Host: i386
Target: i386
Build: Reading specs from /usr/lib/gcc-lib/i686-pc-linux-gnu/3.3.3/spec
Known to work:
Known to fail:
Last reconfirmed:


Note You need to log in before you can comment on or make changes to this bug.
Description Giorgio Alfarano 2004-07-01 08:49:21 UTC
Compiling with -O2 and -O0 the following code i obtain different
result with gcc version > 3.2 ( i tryed 3.3.3,3.3.4)

unsigned char dest[10],source[10]={1,2,3,4,5,6,7,8,9,10};

int main(void)
  int i = 1;
  int step = 1;

  while (i < 8)
    dest[i] = source[(i++*step) % 7];

  for(i=0; i < 8; i++)
    printf("%02x ",dest[i]);



  while (i < 8)
      dest[i] = source[(i*step) % 7];

  for(i=0; i < 8; i++)
    printf("%02x ",dest[i]);



the difference is how dest[i] is addressed via the index i.
Comment 1 Falk Hueffner 2004-07-01 09:08:17 UTC
With -Wall, you get:

test.c:9: warning: operation on `i' may be undefined

and in fact it is; see documentation on -Wsequence-point.
Comment 2 Wolfgang Bangerth 2004-08-13 16:01:37 UTC
Reopening to mark as a duplicate of... 
Comment 3 Wolfgang Bangerth 2004-08-13 16:04:32 UTC
...PR 11751. 

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