This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

c/6765: gcc - incrementation - ternary operator



>Number:         6765
>Category:       c
>Synopsis:       gcc - incrementation - ternary operator
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    unassigned
>State:          open
>Class:          wrong-code
>Submitter-Id:   net
>Arrival-Date:   Wed May 22 04:26:01 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     Pothier Joel
>Release:        gcc 2.95.2 - gcc 2.95.3 - gcc 3.04
>Organization:
>Environment:
gcc 2.95.3, gcc 3.04 (home compiled on Linux Mandrake 8.1)
Mac OS X : gcc 2.95.2
>Description:
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)
>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
>Release-Note:
>Audit-Trail:
>Unformatted:


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]