|Summary:||ptr[i] = ptr[++i]; // works differently with malloc() and -O|
|Component:||rtl-optimization||Assignee:||Not yet assigned to anyone <unassigned>|
|Build:||Known to work:|
|Known to fail:||Last reconfirmed:|
Description robc 2001-12-18 14:56:00 UTC
ptr[i] = ptr[++i]; when ptr is a pointer and compiled with -O then it behaves differently. Release: gcc version 2.95.2 19991024 (release) Environment: Linux 2.2.19, Pentium II How-To-Repeat: compile with "gcc -O"
Comment 1 robc 2001-12-18 14:56:00 UTC
Fix: ptr[i] = ptr[i+1]; i++;
Comment 2 Neil Booth 2001-12-18 15:22:36 UTC
State-Changed-From-To: open->closed State-Changed-Why: Not a bug - you should read up on sequence points. Basically, multiple reads of a variable (i) modified between sequence points is undefined. Your code falls into this category. So, ptr[i] = ptr[++i]; is fundamentally always meaningless.
Comment 3 Andrew Pinski 2005-04-20 02:56:04 UTC
Reopening to ...