3 回答

TA贡献1784条经验 获得超2个赞
你确定是这样定义的!!!
要加续行符吧!
应该是这个样子才对。
#define READ_FIXED(results,keyName) \
{ \
nResult= configfile.readint(-T("fixedCursor"),keyName,ERROR_VAL) \
if(0<nResult&&nResult<m_warrle&&NULL!=m_pcursor[nResult]) \
{ \
results = nResult; \
} \
else \
{ \
results = 0 \
} \
\
}
预编译语句只能定义在同一行,可是同一行写不下许多代码,于是续行符 \ 就派上了用场了。
加上续行符\,预编译器就认为,所有代码都在同一行上了,就把许多行,当作一个完整的宏定义了。
PS:空行也看作一行,也必须有续行符\。
C:标准库的很多函数,都有可能是宏定义。
这是把带参的宏,看作函数使用了。

TA贡献1847条经验 获得超11个赞
#define没什么特别的,就是指定某个字符串由新的名称来替代。
比如#define A "abcdef"
如果你程序中使用A如下
char str[] = A;
预处理阶段,预处理器会替换A为"abcdef"
所以当预处理结束,由编译器编译的时候,得到的实际代码是
char str[] = "abcedf";
同理,如果int m = A;就会报错,因为替换后为int m = "abcedf";这很明显语法错误。
回到你的问题来看
#define READ_FIXED(results,keyName)
{
nResult= configfile.readint(-T("fixedCursor"),keyName,ERROR_VAL)
if(0<nResult&&nResult<m_warrle&&NULL!=m_pcursor[nResult])
{
results = nResult;
}
else
{
results = 0
}
}
这样应该不能通过的,因为,#define 后面的内容必须要在同一行。
所以我觉得你的程序应该有\来把下一行连接到这一行:
#define READ_FIXED(results,keyName)\
{\
nResult= configfile.readint(-T("fixedCursor"),keyName,ERROR_VAL)\
if(0<nResult&&nResult<m_warrle&&NULL!=m_pcursor[nResult])\
{\
results = nResult;\
}\
else\
{\
results = 0\
}\
}
使用时就是是字符串替换的操作而已。
READ_FIXED(m_arrfixedCursor[1],-T("common"))这句就是把results替换为
m_arrfixedCursor[1],-T("common")替换掉keyName,复制{\
nResult= configfile.readint(-T("fixedCursor"),keyName,ERROR_VAL)\
if(0<nResult&&nResult<m_warrle&&NULL!=m_pcursor[nResult])\
{\
results = nResult;\
}\
else\
{\
results = 0\
}\
}替换READ_FIXED(m_arrfixedCursor[1],-T("common"))
- 3 回答
- 0 关注
- 143 浏览
添加回答
举报