public inbox for frysk-bugzilla@sourceware.org
help / color / mirror / Atom feed
* [Bug general/5971] New: Associativity of C operators
@ 2008-03-19 16:11 tthomas at redhat dot com
  2008-03-19 17:04 ` [Bug general/5971] " pmachata at redhat dot com
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: tthomas at redhat dot com @ 2008-03-19 16:11 UTC (permalink / raw)
  To: frysk-bugzilla

Incorrect evaluation for C operators that associate right-to-left.

Frysk:
(fhpd) print i
1
(fhpd) print i++ + ++i + i 
7

But on a GCC compiler:
int i=1;
printf ("%d\n", i++ + ++i + i);

Output: 6


Gdb also seems to have this bug:
(gdb) print i
$2 = 1
(gdb)  print i++ + ++i + i
$3 = 7

-- 
           Summary: Associativity of C operators
           Product: frysk
           Version: unspecified
            Status: NEW
          Severity: normal
          Priority: P2
         Component: general
        AssignedTo: frysk-bugzilla at sourceware dot org
        ReportedBy: tthomas at redhat dot com
OtherBugsDependingO 2246
             nThis:


http://sourceware.org/bugzilla/show_bug.cgi?id=5971

------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.


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

* [Bug general/5971] Associativity of C operators
  2008-03-19 16:11 [Bug general/5971] New: Associativity of C operators tthomas at redhat dot com
@ 2008-03-19 17:04 ` pmachata at redhat dot com
  2008-03-19 17:30 ` tthomas at redhat dot com
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: pmachata at redhat dot com @ 2008-03-19 17:04 UTC (permalink / raw)
  To: frysk-bugzilla


------- Additional Comments From pmachata at redhat dot com  2008-03-19 17:03 -------
I believe this hits undefined behavior, because you change "i" twice between two
sequence points.  I would notabug this.

-- 


http://sourceware.org/bugzilla/show_bug.cgi?id=5971

------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.


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

* [Bug general/5971] Associativity of C operators
  2008-03-19 16:11 [Bug general/5971] New: Associativity of C operators tthomas at redhat dot com
  2008-03-19 17:04 ` [Bug general/5971] " pmachata at redhat dot com
@ 2008-03-19 17:30 ` tthomas at redhat dot com
  2008-03-19 18:30 ` pmachata at redhat dot com
  2008-03-19 19:18 ` tthomas at redhat dot com
  3 siblings, 0 replies; 5+ messages in thread
From: tthomas at redhat dot com @ 2008-03-19 17:30 UTC (permalink / raw)
  To: frysk-bugzilla


------- Additional Comments From tthomas at redhat dot com  2008-03-19 17:30 -------
Even if I do something like: 

(fhpd) print i = 1
1
(fhpd) print i++ + i
3

frysk and gdb gives result 3, whereas C evaluates it to a 2, which is why I
think its a bug with associativity.


-- 


http://sourceware.org/bugzilla/show_bug.cgi?id=5971

------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.


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

* [Bug general/5971] Associativity of C operators
  2008-03-19 16:11 [Bug general/5971] New: Associativity of C operators tthomas at redhat dot com
  2008-03-19 17:04 ` [Bug general/5971] " pmachata at redhat dot com
  2008-03-19 17:30 ` tthomas at redhat dot com
@ 2008-03-19 18:30 ` pmachata at redhat dot com
  2008-03-19 19:18 ` tthomas at redhat dot com
  3 siblings, 0 replies; 5+ messages in thread
From: pmachata at redhat dot com @ 2008-03-19 18:30 UTC (permalink / raw)
  To: frysk-bugzilla


------- Additional Comments From pmachata at redhat dot com  2008-03-19 18:29 -------
But that expression has the same problem.  You can't both change and read the
number in one expression (or, more preciselly, between two sequence points). 
You may want to read the exact wording of the C or C++ standard, but FWIW,
expressions like these always make me feel icky.

-- 


http://sourceware.org/bugzilla/show_bug.cgi?id=5971

------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.


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

* [Bug general/5971] Associativity of C operators
  2008-03-19 16:11 [Bug general/5971] New: Associativity of C operators tthomas at redhat dot com
                   ` (2 preceding siblings ...)
  2008-03-19 18:30 ` pmachata at redhat dot com
@ 2008-03-19 19:18 ` tthomas at redhat dot com
  3 siblings, 0 replies; 5+ messages in thread
From: tthomas at redhat dot com @ 2008-03-19 19:18 UTC (permalink / raw)
  To: frysk-bugzilla


------- Additional Comments From tthomas at redhat dot com  2008-03-19 19:17 -------
Closing bug. 

Would be a neat feature to get frysk to warn users of possibly undefined operations.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED


http://sourceware.org/bugzilla/show_bug.cgi?id=5971

------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.


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

end of thread, other threads:[~2008-03-19 19:18 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-03-19 16:11 [Bug general/5971] New: Associativity of C operators tthomas at redhat dot com
2008-03-19 17:04 ` [Bug general/5971] " pmachata at redhat dot com
2008-03-19 17:30 ` tthomas at redhat dot com
2008-03-19 18:30 ` pmachata at redhat dot com
2008-03-19 19:18 ` tthomas at redhat dot com

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).