揮発性のメモ2

http://d.hatena.ne.jp/iww/

clock_gettime

gettimeofdayの代わりにこれ使えということで
Man page of CLOCK_GETRES
なんでman(2)とman(3)両方にあるんだろう。システムコールかこれ?

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

int main()
{
    struct timespec ts;

    if( clock_gettime(CLOCK_REALTIME,&ts)<0 ){
        perror("clock_gettime");
        exit(1);
    }
    printf("sizeof(tv_sec)=%d\n",sizeof(ts.tv_sec));
    printf("tv_sec  = %ld\n",ts.tv_sec);
    printf("tv_nsec = %ld\n",ts.tv_nsec);

    return 0;
}

librtが必要(-lrt)なのがちょっと鬱陶しい。

struct timespec {
    __time_t tv_sec;
    long int tv_nsec;
}

__time_tの正体はlong int
sizeof(long int)は32ビットOSだと4、64ビットOSだと8 になっているっぽい。


2038年問題に関して、32ビットOSは直す気もなく見捨てられていたらしい。知らなかった。