Thread: get “error :lvalue required as left operand of assignment ” when set value for regist

  1. #1
    Registered User
    Join Date
    Nov 2013
    Posts
    5

    get “error :lvalue required as left operand of assignment ” when set value for regist

    I can not solve this problem. I don't understand why. Here is my simple code


    Code:
    mjpeg.h:
    
        #define START_REG                 (*(volatile unsigned int*) BASE+0x000)  
        #define MJPEG_PIC_START_RD                                  (0x00000001)


    Code:
    mjpeg.c:
        void encStreamInit(void){
        START_REG |= MJPEG_PIC_START_RD;
        }


    Code:
    test.c:
        int main(void){
         encStreamInit();
         return 0;
        }

    It get "error: lvalue required as left operand of assignment" when compiling. Please help me. Thank for your help.

  2. #2
    Registered User
    Join Date
    Jan 2009
    Location
    Australia
    Posts
    375
    From what I can see it looks as if an lvalue is required as the left operand of your assignment .

    START_REG is a macro definition, not a variable. You cannot assign to a macro as it is literally replaced with the expression that you define it as before compilation begins. If BASE is a variable (hopefully it's not because upper case variable names aren't particularly good practice) then it is still wrong because you're dereferencing a variable and then adding something to it which makes it an expression. You can't assign to expressions.

    I'm guessing BASE is probably a defined address and maybe this is like embedded programming or something. I'm fairly sure the same reasoning as above applies. Remember that dereference operator has higher precedence than addition.

  3. #3
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,334
    "*(volatile unsigned int*) BASE+0x000" is not a thing that can be assigned to, since it is an expression. Did you mean to cast "BASE+0x000" to a pointer, then dereference it? If so, your parentheses start in the wrong place for that -- as it is now, BASE is being dereferenced, and then 0x000 is being added to that dereferenced value.

  4. #4
    Registered User
    Join Date
    Nov 2013
    Posts
    5
    Thank you all, I solved the problem.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 10-18-2013, 05:23 PM
  2. error: lvalue required as left operand of assignment
    By rocket_c in forum C Programming
    Replies: 4
    Last Post: 02-11-2013, 12:33 AM
  3. Replies: 10
    Last Post: 11-27-2012, 11:54 AM
  4. error: lvalue required as left operand of assignment
    By owjian1987 in forum C Programming
    Replies: 5
    Last Post: 02-11-2011, 12:34 PM
  5. Replies: 3
    Last Post: 06-01-2010, 06:22 AM

Tags for this Thread