Connecting Tech Pros Worldwide Forums | Help | Site Map

error: non-lvalue in assignment

Newbie
 
Join Date: Jan 2009
Posts: 8
#1: May 12 '09
Hi Everybody

the compiler throws an error when it runs this function in my code, I couldn't figure out what is wrong with my code, please assist me, thanks :).

Expand|Select|Wrap|Line Numbers
  1. void SMAC::IncreaseCW() {
  2. init rI=2;
  3. DATA_CW=DATA_CW*rI;
  4. double cw = (Random::random() % DATA_CW) * slotTime_sec_;
  5. mhCS_.sched(CLKTICK2SEC(difs_) + cw);
  6.  
Expand|Select|Wrap|Line Numbers
  1. mac/smac.cc: In member function `void SMAC::IncreaseCW()':
  2. mac/smac.cc:463: error: non-lvalue in assignment
  3.  

Banfa's Avatar
AdministratorVoR
 
Join Date: Feb 2006
Location: South West UK
Posts: 6,171
#2: May 12 '09

re: error: non-lvalue in assignment


Quote:
init rI=2;
Did you mean int?
JosAH's Avatar
Expert
 
Join Date: Mar 2007
Posts: 10,611
#3: May 12 '09

re: error: non-lvalue in assignment


Quote:

Originally Posted by Banfa View Post

Did you mean int?

DATA_CW suggests to be a macro name ... who knows?

kind regards,

Jos
Newbie
 
Join Date: Jan 2009
Posts: 8
#4: May 12 '09

re: error: non-lvalue in assignment


sorry folks, i meant
Quote:
int rI = 2;
im still facing the same error, any help? thx :)
Familiar Sight
 
Join Date: Mar 2007
Posts: 148
#5: May 12 '09

re: error: non-lvalue in assignment


Your error says line 463. Which of those lines is 463?

You have an assignment involving something called DATA_CW, but you didn't post the code which defines DATA_CW.

More info == more help.
JosAH's Avatar
Expert
 
Join Date: Mar 2007
Posts: 10,611
#6: May 12 '09

re: error: non-lvalue in assignment


Quote:

Originally Posted by muby View Post

sorry folks, i meant

im still facing the same error, any help? thx :)

Did you read the error message and did you check the line your compiler complained about? Learn how to read error messages; it'll be a lot faster than posting here everytime you see one.

kind regards,

Jos
Newbie
 
Join Date: Jan 2009
Posts: 8
#7: May 12 '09

re: error: non-lvalue in assignment


Thanks for your reply, the line where im getting error is shown below,
I defined DATA_CW in header file as
Quote:
#define DATA_CW 63
Expand|Select|Wrap|Line Numbers
  1. # void SMAC::IncreaseCW() {
  2. # int rI=2;
  3. # DATA_CW=DATA_CW*rI; # error is in this line (line 463)
  4. # double cw = (Random::random() % DATA_CW) * slotTime_sec_;
  5. # mhCS_.sched(CLKTICK2SEC(difs_) + cw);
  6. }
Needs Regular Fix
 
Join Date: Jul 2008
Posts: 383
#8: May 12 '09

re: error: non-lvalue in assignment


After preprocessing it's expanded to
63 = 63*2;

Left part is a number here, you can't assign to numbers. What are you trying to do?
Newbie
 
Join Date: Jan 2009
Posts: 8
#9: May 12 '09

re: error: non-lvalue in assignment



IncreaseCW
should increases the value of DATA_CW by doubling the old value of DATA_CW, and assigne the new value back to DATA_CW. this new value will be used in other functions.

I changed it as shown below, but im still getting the same error.

Expand|Select|Wrap|Line Numbers
  1. void SMAC::IncreaseCW() {
  2. int DATA_CW_new;
  3. DATA_CW_new = (DATA_CW*rateincrease);
  4. DATA_CW = DATA_CW_new;
  5. double cw = (Random::random() % DATA_CW) * slotTime_sec_;
  6. mhCS_.sched(CLKTICK2SEC(difs_) + cw);
  7. }
Familiar Sight
 
Join Date: Mar 2007
Posts: 148
#10: May 12 '09

re: error: non-lvalue in assignment


Read newb16's post again.
DATA_CW is a macro, not a variable. It is replaced by the compiler with '63' wherever it occurs in your code. You cannot assign to it. Use a variable.
Newbie
 
Join Date: Jan 2009
Posts: 8
#11: May 12 '09

re: error: non-lvalue in assignment


Thanks alot, that fixed my error :)
Reply

Tags
c++, error, non-lvalue in assignment