今日在看程序时,发现一个函数中运用的许多的
#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.2dr”,TY, TM, TD,THH, TMM, TSS);
}