您的位置:首页 > 其它

宏定义中Error[Pe029]: expected an expression

2016-03-11 22:47 621 查看
在定义读写字节宏时出现Error[Pe029]: expected an expression。

我的定义如下:

#define READ_RAM(p, type)  (*(((type)*)(p)))//错误
#define READ_RAM8(p)           READ_RAM(p, u8)
用法:
u8 test = 0;
u8 *p = &test;
u8 value = READ_RAM8(p);//Error[Pe029]: expected an expression
后来逐步推敲,验证。终于搞清楚
u8 value = *((u8 *)(p));//OK
u8 value = *(((u8) *)(p));//error
所以,正确写法是:

#define READ_RAM(p, type)  (*((type *)(p)))//错误
#define READ_RAM8(p)           READ_RAM(p, u8)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: