Webinars, Moodle, Gerencia de e-Learning

2010-06-01 Thread Net-Learning
This is a message in multipart MIME format.  Your mail client should not be 
displaying this. Consider upgrading your mail client to view this message 
correctly.



Bug in gcc 3?

2010-06-01 Thread Tim van der Molen
I'm running i386 -current of 13 May and ran into surprising behaviour
from gcc. Consider the following code snippet:

int i;

i = 1;
if (i += 1 == 2)
printf(%d; should be 2\n, i);

i = 1;
if ((i += 1) == 2)
printf(%d; should be 2\n, i);

The output is:

1; should be 2
2; should be 2

It seems gcc parses the += statement wrongly: a += b == c should be
interpreted as something like (a = a + b) == c, but instead gcc seems
to interpret it as a = (a + b == c). That would explain why i equals 1
in the first line of output.

Would this be a bug in gcc or am I overlooking something?

Regards,
Tim



Re: Bug in gcc 3?

2010-06-01 Thread Joerg Sonnenberger
On Tue, Jun 01, 2010 at 09:14:53PM +0200, Tim van der Molen wrote:
 Would this be a bug in gcc or am I overlooking something?

== has a higher precendence than += and therefore binds stronger.
See operator(7).

Joerg



Re: Bug in gcc 3?

2010-06-01 Thread Nikolai Fetissov
 I'm running i386 -current of 13 May and ran into surprising behaviour
 from gcc. Consider the following code snippet:

   int i;

   i = 1;
   if (i += 1 == 2)
   printf(%d; should be 2\n, i);

   i = 1;
   if ((i += 1) == 2)
   printf(%d; should be 2\n, i);

 The output is:

   1; should be 2
   2; should be 2

 It seems gcc parses the += statement wrongly: a += b == c should be
 interpreted as something like (a = a + b) == c, but instead gcc seems
 to interpret it as a = (a + b == c). That would explain why i equals 1
 in the first line of output.

 Would this be a bug in gcc or am I overlooking something?

== has higher precedence then += so the first
expression is parsed as ( i += ( 1 == 2 )).

--
 Nikolai



Re: Bug in gcc 3?

2010-06-01 Thread Jonathan Gray
On Tue, Jun 01, 2010 at 09:14:53PM +0200, Tim van der Molen wrote:
 I'm running i386 -current of 13 May and ran into surprising behaviour
 from gcc. Consider the following code snippet:
 
   int i;
 
   i = 1;
   if (i += 1 == 2)
   printf(%d; should be 2\n, i);
 
   i = 1;
   if ((i += 1) == 2)
   printf(%d; should be 2\n, i);
 
 The output is:
 
   1; should be 2
   2; should be 2
 
 It seems gcc parses the += statement wrongly: a += b == c should be
 interpreted as something like (a = a + b) == c, but instead gcc seems
 to interpret it as a = (a + b == c). That would explain why i equals 1
 in the first line of output.
 
 Would this be a bug in gcc or am I overlooking something?

yes, you are overlooking normal operator precedence rules.