sakurapyon’s blog

sakurapyon’s blog

わからん…

なんで後者だけ指摘される?

$ cat a.c
#include        <stdio.h>
#include        <stdint.h>

int
main()
{
        typedef unsigned int ui_t;
        typedef unsigned long ul_t;
        typedef unsigned long long ull_t;

        ui_t    ui=0;
        ul_t    ul=0;
        ull_t   ull=0;

        printf("%u\n",ui);
        printf("%lu\n",ul);
        printf("%llu\n",ull);

        uint16_t        u16=0;
        uint32_t        u32=0;
        uint64_t        u64=0;

        printf("%u\n",u16);
        printf("%lu\n",u32);
        printf("%llu\n",u64);

        return 0;
}
$ g++ -Wall a.c
a.c: In function ‘int main()’:
a.c:24: 警告: format ‘%lu’ expects type ‘long unsigned int’, but argument 2 has type ‘uint32_t’
a.c:25: 警告: format ‘%llu’ expects type ‘long long unsigned int’, but argument 2 has type ‘uint64_t’
$ grep uint[0-9] /usr/include/stdint.h
typedef unsigned char           uint8_t;
typedef unsigned short int      uint16_t;
#ifndef __uint32_t_defined
typedef unsigned int            uint32_t;
# define __uint32_t_defined
typedef unsigned long int       uint64_t;
typedef unsigned long long int  uint64_t;
$ g++ -v
Using built-in specs.
Target: x86_64-redhat-linux
コンフィグオプション: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre --enable-libgcj-multifile --enable-java-maintainer-mode --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib --with-ppl --with-cloog --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux
スレッドモデル: posix
gcc version 4.4.6 20110731 (Red Hat 4.4.6-3) (GCC)