请教傻孩子关于条件编译
条件编译能否可以这样写?如:
#define NUMBER 3
void main()
{
#if NUMBER==1
{
;
}
#endif
#if NUMBER==2
{
;
}
#endif
#if NUMBER==3
{
;
}
#endif
#if NUMBER==4
{
;
}
#endif
#if NUMBER==5
{
;
}
#endif
} 连括号都不需要吧 我如果加上
#if NUMBER==3
{
;
}
就报错
!E E:(129):unrecognized statement
!E E:(129): syntax error; found `(' expecting `;'
!W E:130): expression with no effect elided
!E E:(130): syntax error; found `{' expecting `;'
Done: there are error(s). Exit code: 1 129和130行是哪一行? 暂时不管报错了,首先这种写法有没有问题,ICC允许这样写吗? 这和ICC无关吧? 都支持这么写的... to 【4楼】 lizihui
没有问题,如果有错误,请检查是否代码的前面有错误,或者含有非法的中文字符…… 这种写法是可以的,我刚刚试试了下,
#define NUMBER 3
int main(void)
{
#if NUMBER==1
{
;
}
#elseif NUMBER==2
{
;
}
#elseif NUMBER==3
{
;
}
#elseif NUMBER==4
{
;
}
#elseif NUMBER==5
{
;
}
#endif
return 0;
}
编译结果:
CPU: ATmega16
Program memory usage: 158 bytes, 0.96% full.
Eeprom memory usage: 0 bytes, 0.00% full.
Global variables usage: 0 bytes
atmantest.elf - 0 error(s), 0 warning(s)
编译器为atmanavr 谢谢小马哥哈!我本想把有些函数写成库函数,但对条件编译还不精通,而且感觉功力还不够,暂时放弃了,现在还是针对固定的硬件写程序 楼上,有空可以研究下usbasp的源码,非常受益,呵呵。 这种代码在不通平台移植不错。学习了。
页:
[1]