今天在看程序时,发现一个函数中使用的很多的 #if 1 ...... #endif #if 0 ...... #endif 因为没有用过,感到有点莫名。如是上网查找答案。终于明白是用来注释编译内容的。意思是说: #if 1 需要编译器编译以下内容; #if 0 编译器不要编译以下内容; #if 0 #endif 这种用法还可以实现“注释嵌套!!!”//如果用的话,中间的代码不能加注释。这样不利于调试。 例如: void Time_Display(u32 TimeVar)
{
#if 1
u32 TY = 0, TM = 1, TD = 0;
s32 Num4Y,NumY, OffSec, Off4Y = 0;
u32 i;
s32 NumDay; //OffDay;
#endif
u32 THH = 0, TMM = 0, TSS = 0;
#if 0
THH = TimeVar/3600;
TMM = (TimeVar % 3600)/60;
TSS = (TimeVar % 3600)% 60;
#endif
#if 1
{
Num4Y = TimeVar/SecsPerFourYear;
OffSec = TimeVar%SecsPerFourYear; i=1;
while(OffSec > Year_Secs_Accu[i++])
Off4Y++;
NumY = Num4Y*4 + Off4Y;
TY = 2000+NumY;
OffSec = OffSec - Year_Secs_Accu[i-2];
i=0;
if(TY%4)
{ // common year
while(OffSec > Month_Secs_Accu_C[i++]);
TM = i-1;
OffSec = OffSec - Month_Secs_Accu_C[i-2];
}
else
{ // leap year
while(OffSec > Month_Secs_Accu_L[i++]);
TM = i-1;
OffSec = OffSec - Month_Secs_Accu_L[i-2];
}
NumDay = OffSec/SecsPerDay;
OffSec = OffSec%SecsPerDay;
TD = NumDay+1;
THH = OffSec/3600;
TMM = (OffSec % 3600)/60;
TSS = (OffSec % 3600)% 60;
}
#endif printf("Date: %0.4d-%0.2d-%0.2d Time: %0.2d:%0.2d:%0.2d\r",TY, TM, TD,THH, TMM, TSS);
} |