もぐてっく

人は1つ歳をとるたび、1ビットづつ大きくなれると信じてた。

long long intが妙

long long intな値をprintfしようとしてハマったので記載。

#include <stdio.h>

int main(int argc, char *argv[])
{
        long long int a = 1234567890LL;
        long long int b = 2345678901LL;

        printf("OK:%lld,%lld\n", a, b);
        printf("NG:%d,%lld\n", a, b);
        printf("Strange:%d,%d,%lld\n", a, b);

        return 0;
}
OK:1234567890,2345678901
NG:1234567890,-8372129906997329920
Strange:1234567890,0,2345678901


long long intを%dで受けるとアドレス?が4バイトしか進まないみたい。
Mint11のgccだとwarningが出るみたいだけど、仕事で使ってるそれは出なかったような・・・。

warning: format ‘%d’ expects type ‘int’, but argument 2 has type ‘long long int’