This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
C++ Bug or (my) Interpretation error
- From: Arthur Schwarz <aschwarz1309 at verizon dot net>
- To: gcc-help at gcc dot gnu dot org
- Date: Sun, 14 Sep 2008 12:23:54 -0700 (PDT)
- Subject: C++ Bug or (my) Interpretation error
- Reply-to: aschwarz1309 at verizon dot net
For the Short Code Snippet we have the Following Results. I am using gcc-version 3.4.4 under Cygwin.
I would have expected the 2nd result to have been equal with the post-increment occurring after the comparison operation. Does the precedence of the closing ')' force the unary post-increment to execute before the comparison operation.
I would have expected that the last result would have been not equal. What seems to be happening is either the original 'num' is being compared to itself or the pre-increment 'num' is being compared to itself. At first blush, this appears wrong. Have I misunderstood the semantics?
skidmarks
/************** Short Code Snippet *************/
int main() {
int num = 10;
if ( num++ == num ) { printf("( num++ == num )\n"); }
else { printf("( num++ != num )\n"); }
if ( num == num++) { printf("( num == num++)\n"); }
else { printf("( num != num++)\n"); }
if (++num == num) { printf("(++num == num )\n"); }
else { printf("(++num != num )\n"); }
if ( num == ++num) { printf("( num == ++num)\n"); }
else { printf("( num != ++num)\n"); }
}
/************** Following Results *************/
( num++ != num ) OK
( num != num++) Not so OK
(++num == num ) OK
( num == ++num) Not So OK