需要左值的左值

问题描述 投票:0回答:1

同时编译此代码:

#define SET_BIT(reg,bitno)          reg|=(1<<bitno)
#define CLR_BIT(reg,bitno)          reg &=~(1<<bitno)
#define GET_BIT(reg,bitno)          ((reg>>bitno)&1)
#define TOGGLE_BIT(reg,bitno)       reg^=(1<<bitno)

switch (PIN_select){

     case DIO_PIN_A:
        if (level==LOW)
            CLR_BIT(DIO_PIN_A,PIN_Bit);
        else if(level==HIGH)
            SET_BIT(DIO_PIN_A,PIN_Bit);
     break;
}

我遇到以下错误:

 error: lvalue required as left operand of assignment fac(0)=1;
 error: lvalue required as left operand of assignmen
 error: lvalue required as left operand of assignment
 #define CLR_BIT(REG,BIT) REG &=~(1<<BIT)
                              ^
 note: in expansion of macro ‘CLR_BIT’
CLR_BIT(DIO_PIN_A,PIN_Bit);
    ^
 error: lvalue required as left operand of assignment
 #define SET_BIT(REG,BIT) REG|=(1<<BIT)
                             ^
c lvalue
1个回答
1
投票

例如,此行

CLR_BIT(DIO_PIN_A,PIN_Bit);

扩展到:

DIO_PIN_A &= ~(1<<PIN_Bit);

但是,DIO_PIN_A是整数常数(我们知道,因为在case中使用了它,所以您不能对其进行修改。

© www.soinside.com 2019 - 2024. All rights reserved.