119

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.

2
  • 44
    As an update to this: MSVC 2010 now includes stdint.h Nov 24, 2010 at 3:12
  • Going by this blog: blogs.msdn.com/b/vcblog/archive/2014/11/17/…, VS 2015 Preview fully supports the C99 Standard Library (with the only omissions being tgmath.h, which requires C compiler magic and is not relevant to C++ which has overloading, and CX_LIMITED_RANGE/FP_CONTRACT which also require compiler support). Dec 14, 2014 at 3:48

7 Answers 7

85

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

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

Thanks to the Software Ramblings blog.

NB: The Public Domain version of the header, mentioned by Michael Burr in a comment, can be find as an archived copy here. An updated version can be found in the Android source tree for libusb_aah.

3
49

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

1
  • 3
    As well as <cstdint> for C++ users who like it in std::. Sep 12, 2012 at 16:45
49

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
2
  • 4
    Am I missing something or shouldn't it be typedef unsigned __int64 uint64_t; ? Dec 5, 2010 at 8:55
  • 1
    And to use literal uint64_t values it is useful to #define U64(u) (u##ui64) on Windows and to #define U64(u) (u##ULL) otherwise.
    – Niklas
    Aug 14, 2013 at 11:12
25

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

0
11

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

3
  • 1
    boost is C++, the question is on C99
    – Remo.D
    Sep 24, 2008 at 14:11
  • 4
    It is not clear - he is asking about a C99 header in Visual Studio, without specifying which language he is using. In any case it can't be C99 because Microsoft does not support it. Sep 24, 2008 at 14:36
  • OP wants a copy of <stdint.h>, not a Boost header.
    – jww
    Oct 1, 2016 at 8:16
6

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++.

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++.

4

Another portable solution:

POSH: The Portable Open Source Harness

"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."

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

-Jason

2
  • 1
    From Poshlib Wikipedia article, the link authorization is:username: guest, password: guest123
    – JPaget
    Sep 13, 2012 at 23:19
  • Grand total of 3 commits, last one dated September 2006
    – AntoineL
    Feb 21, 2015 at 11:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.