the ternary operator causes incrementation of left hand side expression to occurs before it should in an expression where the variable appears at both side of the affectation expression. example: *s++ = (*s == 'x') ? 'X': *s; Note: this does not appears in gcc-2.96 (Mandrake 8.2) Release: gcc 2.95.2 - gcc 2.95.3 - gcc 3.04 Environment: gcc 2.95.3, gcc 3.04 (home compiled on Linux Mandrake 8.1) Mac OS X : gcc 2.95.2 How-To-Repeat: #include <stdio.h> #define STRING "abc" int main() { char s[10], *t; strcpy(s, STRING); t = s; while (*t != '\0') *t++ = (*t == 'b') ? 'X': *t; /* this print "Xc" instead of "aXc" */ printf("%s\n",s); }
Fix: Must replace ternary operator by if/else instruction
State-Changed-From-To: open->closed State-Changed-Why: Not a bug. The standard states that whether the LHS or the RHS of '=' is evaluated first is undefined. You were lucky before.
Reopening to ...
a dup of bug 11751 *** This bug has been marked as a duplicate of 11751 ***