Small Question on statement a = ( b() != c )

Go To Last Post
8 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

hi all..

I recently came through this like a statement in AVR c project ,and I was wondering whether it is an augmented assignment or a comparison..

a = ( b() != c );
a = ( b != c );

Any help is much appreciated..

thanks.

BR
Kanishka

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The compiler will evaluate :
1. b()
2. compare it with c. true or false.
3. assign the result to a.

I have no idea what an "augmented assignment" is.

Note that the order of evaluation could be completely different if you had changed the parentheses.

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

"!=" is an operator like any other with a well defined result (0 if both operands are equal, 1 otherwise). And of course it is also possible to assign this result to a variable.

Stefan Ernst

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Stefan and David..

Thanks a lot for your reply.

BR
Kanishka

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi all,

I tried the result to verify this by myself. but the results were not to the expectation..

#include
using namespace std;

int main()
{
	int a,b,c=10;
	a = (b == c);
	cout<<a<<"\n";
	a = (b != c);
	cout<<a<<"\n";	
	
}

the output was 0 1 instead of 1 0 which was expected..
anything wrong here.. ??

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

b has an unspecific random content, so how can you expect something specific?
In your case the random content of b is obviously not 10.

Stefan Ernst

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
int main() 
{ 
   int a,b,c=10; 
   a = (b == c);

2 of the 3 LOCAL vars. are uninitialized so you can't know what value b will start with. So b == c, tests for equality and is FALSE, etc. from there. You need a good book on C.

1) Studio 4.18 build 716 (SP3)
2) WinAvr 20100110
3) PN, all on Doze XP... For Now
A) Avr Dragon ver. 1
B) Avr MKII ISP, 2009 model
C) MKII JTAGICE ver. 1

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ohhhhh...

Sorry for the silly question and thanks a lot for your help and time..

BR