c語言 --- printf time_t 注意點


先看看寫的測試代碼

#include <stdio.h>
#include <time.h>

int main(int argc, char* argv[])
{
    time_t now;

    time(&now);
    printf("size of time_t: %d\r\n", sizeof(time_t)); //1
    printf("%d -> %d\r\n", now, now); //Error 2.
    printf("%I64d -> %I64d\r\n", now, now); // for windows 3.
    printf("%lld -> %lld\r\n", now, now); // for linux 4.
    return 0;
}

輸出:

size of time_t: 8
1350547419 -> 0
1350547419 -> 1350547419
1350547419 -> 1350547419

原因:

  第二個printf參數把把time_t結構分成了兩個32位的INT。所以這二個參數為0。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM