C++ C99 stdint.h 标头和 MS Visual Studio

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/126279/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 13:03:39  来源:igfitidea点击:

C99 stdint.h header and MS Visual Studio

c++cvisual-studioc99

提问by Rob

To my amazement I just discovered that the C99 stdint.h is missing from MS Visual Studio 2003 upwards. I'm sure they have their reasons, but does anyone know where I can download a copy? Without this header I have no definitions for useful types such as uint32_t, etc.

令我惊讶的是,我刚刚发现 MS Visual Studio 2003 以上缺少 C99 stdint.h。我相信他们有他们的理由,但有谁知道我可以在哪里下载副本?没有这个头文件,我就没有有用类型的定义,比如 uint32_t 等。

采纳答案by Rob

Turns out you can download a MS version of this header from:

原来您可以从以下位置下载此标头的 MS 版本:

https://github.com/mattn/gntp-send/blob/master/include/msinttypes/stdint.h

https://github.com/mattn/gntp-send/blob/master/include/msinttypes/stdint.h

A portable one can be found here:

可在此处找到便携式设备:

http://www.azillionmonkeys.com/qed/pstdint.h

http://www.azillionmonkeys.com/qed/pstdint.h

Thanks to the Software Ramblings blog.

感谢Software Rambling的博客。

回答by Nicholas Mancuso

Just define them yourself.

只需自己定义它们。

#ifdef _MSC_VER

typedef __int32 int32_t;
typedef unsigned __int32 uint32_t;
typedef __int64 int64_t;
typedef unsigned __int64 uint64_t;

#else
#include <stdint.h>
#endif

回答by Ashwin Nanjappa

Update: Visual Studio 2010and Visual C++ 2010 Expressboth have stdint.h. It can be found in C:\Program Files\Microsoft Visual Studio 10.0\VC\include

更新:Visual Studio 2010Visual C++ 2010 Express都有stdint.h. 它可以在C:\Program Files\Microsoft Visual Studio 10.0\VC\include

回答by Adam Mitz

Visual Studio 2003 - 2008 (Visual C++ 7.1 - 9) don't claim to be C99 compatible. (Thanks to rdentato for his comment.)

Visual Studio 2003 - 2008 (Visual C++ 7.1 - 9) 不声称与 C99 兼容。(感谢 rdentato 的评论。)

回答by Nemanja Trifunovic

Boost contains cstdint.hpp header file with the types you are looking for: http://www.boost.org/doc/libs/1_36_0/boost/cstdint.hpp

Boost 包含 cstdint.hpp 头文件,其中包含您要查找的类型:http: //www.boost.org/doc/libs/1_36_0/boost/cstdint.hpp

回答by Mike Dimmick

Microsoft do not support C99 and haven't announced any plans to. I believe they intend to track C++ standards but consider C as effectively obsolete except as a subset of C++.

微软不支持 C99,也没有宣布任何计划。我相信他们打算跟踪 C++ 标准,但认为 C 除了作为 C++ 的一个子集之外实际上已经过时了。

New projects in Visual Studio 2003 and later have the "Compile as C++ Code (/TP)" option set by default, so any .c files will be compiled as C++.

Visual Studio 2003 及更高版本中的新项目默认设置了“编译为 C++ 代码 (/TP)”选项,因此任何 .c 文件都将编译为 C++。

回答by Jason Harrison

Another portable solution:

另一个便携式解决方案:

POSH: The Portable Open Source Harness

POSH:便携式开源工具

"POSH is a simple, portable, easy-to-use, easy-to-integrate, flexible, open source "harness" designed to make writing cross-platform libraries and applications significantly less tedious to create and port."

“POSH 是一种简单、便携、易于使用、易于集成、灵活、开源的“工具”,旨在使编写跨平台库和应用程序的创建和移植工作大大减少。”

http://poshlib.hookatooka.com/poshlib/trac.cgi

http://poshlib.hookatooka.com/poshlib/trac.cgi

as described and used in the book: Write portable code: an introduction to developing software for multiple platforms By Brian Hook http://books.google.ca/books?id=4VOKcEAPPO0C

如书中所述和使用:编写可移植代码:多平台软件开发介绍 作者:Brian Hook http://books.google.ca/books?id=4VOKcEAPPO0C

-Jason

-杰森