error: non-lvalue in assignment

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • muby
    New Member
    • Jan 2009
    • 8

    error: non-lvalue in assignment

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

    Code:
    void SMAC::IncreaseCW() {
    init rI=2;
    DATA_CW=DATA_CW*rI;
    double cw = (Random::random() % DATA_CW) * slotTime_sec_;
    mhCS_.sched(CLKTICK2SEC(difs_) + cw);
    Code:
    mac/smac.cc: In member function `void SMAC::IncreaseCW()':
    mac/smac.cc:463: error: non-lvalue in assignment
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    init rI=2;
    Did you mean int?

    Comment

    • JosAH
      Recognized Expert MVP
      • Mar 2007
      • 11453

      #3
      Originally posted by Banfa
      Did you mean int?
      DATA_CW suggests to be a macro name ... who knows?

      kind regards,

      Jos

      Comment

      • muby
        New Member
        • Jan 2009
        • 8

        #4
        sorry folks, i meant
        int rI = 2;
        im still facing the same error, any help? thx :)

        Comment

        • scruggsy
          New Member
          • Mar 2007
          • 147

          #5
          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.

          Comment

          • JosAH
            Recognized Expert MVP
            • Mar 2007
            • 11453

            #6
            Originally posted by muby
            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

            Comment

            • muby
              New Member
              • Jan 2009
              • 8

              #7
              Thanks for your reply, the line where im getting error is shown below,
              I defined DATA_CW in header file as
              #define DATA_CW 63
              Code:
              # void SMAC::IncreaseCW() {
              # int rI=2;
              # DATA_CW=DATA_CW*rI; [B][U]# error is in this line (line 463)[/U][/B]
              # double cw = (Random::random() % DATA_CW) * slotTime_sec_;
              # mhCS_.sched(CLKTICK2SEC(difs_) + cw);
              }

              Comment

              • newb16
                Contributor
                • Jul 2008
                • 687

                #8
                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?

                Comment

                • muby
                  New Member
                  • Jan 2009
                  • 8

                  #9

                  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.

                  Code:
                  void SMAC::IncreaseCW() {
                  int DATA_CW_new;
                  DATA_CW_new = (DATA_CW*rateincrease);
                  DATA_CW = DATA_CW_new;
                  double cw = (Random::random() % DATA_CW) * slotTime_sec_;
                  mhCS_.sched(CLKTICK2SEC(difs_) + cw);
                  }

                  Comment

                  • scruggsy
                    New Member
                    • Mar 2007
                    • 147

                    #10
                    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.

                    Comment

                    • muby
                      New Member
                      • Jan 2009
                      • 8

                      #11
                      Thanks alot, that fixed my error :)

                      Comment

                      Working...