public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* Re: c/6765: gcc - incrementation - ternary operator
@ 2002-05-22  5:03 neil
  0 siblings, 0 replies; 2+ messages in thread
From: neil @ 2002-05-22  5:03 UTC (permalink / raw)
  To: gcc-bugs, gcc-prs, jompo, nobody

Synopsis: gcc - incrementation - ternary operator

State-Changed-From-To: open->closed
State-Changed-By: neil
State-Changed-When: Wed May 22 05:03:03 2002
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.

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=6765


^ permalink raw reply	[flat|nested] 2+ messages in thread

* c/6765: gcc - incrementation - ternary operator
@ 2002-05-22  4:26 jompo
  0 siblings, 0 replies; 2+ messages in thread
From: jompo @ 2002-05-22  4:26 UTC (permalink / raw)
  To: gcc-gnats


>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:


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2002-05-22 12:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-05-22  5:03 c/6765: gcc - incrementation - ternary operator neil
  -- strict thread matches above, loose matches on Subject: below --
2002-05-22  4:26 jompo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).