#if 0用法和 #if 1 用法
#if 1
......
#endif
#if 0
......
#endif
因?yàn)闆](méi)有用過(guò),感到有點(diǎn)莫名。如是上網(wǎng)查找答案。終于明白是用來(lái)注釋編譯內(nèi)容的。意思是說(shuō):
#if 1 需要編譯器編譯以下內(nèi)容;
#if 0 編譯器不要編譯以下內(nèi)容;
#if 0 #endif 這種用法還可以實(shí)現(xiàn)“注釋嵌套?。?!”
例如:
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);
}
評(píng)論