1

I am working on raspberry pi.and writing code for Keypad in linux. I have defined a macro

#define ALL_COL_HIGH  ((GPIO_SET(COL1) | GOIO_SET(COL2) | GPIO_SET(COL3) | GPIO__SET(COL4)))

Whenever i am using ALL_COL_HIGH getting error: lvalue required as left operand of assignment, and set function definition is

#define GPIO_SET(g)  *(gpio.addr + 7) |=  (1<<(g))
1
  • A pair of parenthesis might fix the issue.
    – devnull
    Commented Mar 29, 2014 at 9:53

1 Answer 1

3

An advise: always close body of an expression macro into parenthesis:

#define GPIO_SET(g)  (*(gpio.addr + 7) |=  (1<<(g)))

Using your original macros, the macro ALL_COL_HIGH was expanded into something like:

((  *(gpio.addr + 7) |=  (1<<(g)) |   *(gpio.addr + 7) |=  (1<<(g)) | ....   ))

which is parsed as:

((  *(gpio.addr + 7) |=  ( (1<<(g)) | *(gpio.addr + 7) ) |=  ((1<<(g)) | ....  ))

from where you can see that on the left side of the assignment ((1<<(g)) | *(gpio.addr + 7)) |= ... there is an expression which is not an l-value.

Closing the body of GPIO_SET into parenthesis will fix the problem.

Not the answer you're looking for? Browse other questions tagged or ask your own question.