Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C stdint.h和inttypes.h之间的差异_C_Uint64_Stdint - Fatal编程技术网

C stdint.h和inttypes.h之间的差异

C stdint.h和inttypes.h之间的差异,c,uint64,stdint,C,Uint64,Stdint,stdint.h和inttypes.h之间有什么区别 如果未使用其中任何一种类型,则无法识别uint64,但使用其中任何一种类型都是已定义的类型。 使用stdint.h获得一组最小的定义;如果您还需要在printf、scanf等中为这些文件提供便携支持,请使用inttypes.h。stdint.h 如果要使用指定宽度的整数类型C99(即int32\u t,uint16\u t等),则包含此文件是“最低要求”。 如果包含此文件,则将获得这些类型的定义,以便能够在变量和函数声明中使用这些类型,并对这

stdint.h和inttypes.h之间有什么区别

如果未使用其中任何一种类型,则无法识别uint64,但使用其中任何一种类型都是已定义的类型。

使用stdint.h获得一组最小的定义;如果您还需要在printf、scanf等中为这些文件提供便携支持,请使用inttypes.h。

stdint.h 如果要使用指定宽度的整数类型C99(即
int32\u t
uint16\u t
等),则包含此文件是“最低要求”。 如果包含此文件,则将获得这些类型的定义,以便能够在变量和函数声明中使用这些类型,并对这些数据类型执行操作

inttypes.h 如果包含此文件,将获得stdint.h提供的所有内容(因为inttypes.h包括stdint.h),但是还将获得以可移植方式使用这些类型执行
printf
scanf
(和
fprintf
fscanf
,等等)的工具。例如,您将获得
PRIu64
宏,这样您就可以
printf
a
uint64\u t
如下所示:

#include <stdio.h>
#include <inttypes.h>
int main (int argc, char *argv[]) {

    // Only requires stdint.h to compile:
    uint64_t myvar = UINT64_C(0) - UINT64_C(1);

    // Requires inttypes.h to compile:
    printf("myvar=%" PRIu64 "\n", myvar);  
}

inttypes.h
#include
s stdint.h.I在阅读了wiki文章后来到stackoverflow学习stdint.h和inttypes.h之间的区别,这篇文章告诉我,(u)intN\t在这两种版本中都可用。那么有什么区别呢?我应该包括哪些?包括并添加一些printf宏。请参阅下面MikkoÖstlund的答案。我得到:
致命错误:inttypes.h:没有这样的文件或目录
谢谢,这是一个很好的答案(尽管我没有问最初的问题!)。为了补充Mikko的答案,inttypes.h复制到stdint.h中(通过预处理器
#include
)。至少在我的Linux系统上(GCC4.5.2和类似版本)。
#include <stdio.h>
#include <stdint.h>
int main (int argc, char *argv[]) {

    // Only requires stdint.h to compile:
    uint64_t myvar = UINT64_C(0) - UINT64_C(1);

    // Not recommended.
    // Requires different cases for different operating systems,
    //  because 'PRIu64' macro is unavailable (only available 
    //  if inttypes.h is #include:d).
    #ifdef __linux__
        printf("myvar=%lu\n", myvar);
    #elif _WIN32
        printf("myvar=%llu\n", myvar);
    #endif
}