Summary: | ptr[i] = ptr[++i]; // works differently with malloc() and -O | ||
---|---|---|---|
Product: | gcc | Reporter: | robc |
Component: | rtl-optimization | Assignee: | Not yet assigned to anyone <unassigned> |
Status: | RESOLVED DUPLICATE | ||
Severity: | normal | CC: | gcc-bugs, neil |
Priority: | P3 | Keywords: | wrong-code |
Version: | 2.95.2 | ||
Target Milestone: | --- | ||
Host: | Target: | ||
Build: | Known to work: | ||
Known to fail: | Last reconfirmed: | ||
Attachments: | test.c |
Description
robc
2001-12-18 14:56:00 UTC
Fix: ptr[i] = ptr[i+1]; i++; 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. Reopening to ... |