118

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.

Rob
  • 76,700
  • 56
  • 158
  • 197
  • 43
    As an update to this: MSVC 2010 now includes `stdint.h` – Michael Burr Nov 24 '10 at 03:12
  • Going by this blog: http://blogs.msdn.com/b/vcblog/archive/2014/11/17/c-11-14-17-features-in-vs-2015-preview.aspx, *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).* – vulcan raven Dec 14 '14 at 03:48

7 Answers7

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.

0xC0000022L
  • 20,597
  • 9
  • 86
  • 152
Rob
  • 76,700
  • 56
  • 158
  • 197
  • 14
    A public domain (not an MIT/BSD license - you don't even need to keep a copyright attribution around) stdint.h for MSVC (a slightly modified version from MinGW): http://snipplr.com/view/18199/stdinth/ – Michael Burr Oct 23 '09 at 07:32
  • The first link 404s – Matthew Moisen Jul 23 '16 at 19:42
  • Modified the original answer but: https://github.com/mattn/gntp-send/blob/master/include/msinttypes/stdint.h the svn link is dead – smaudet Oct 29 '16 at 20:26
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
Craig McQueen
  • 41,871
  • 30
  • 130
  • 181
Nicholas Mancuso
  • 11,599
  • 6
  • 45
  • 47
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

Ashwin Nanjappa
  • 76,204
  • 83
  • 211
  • 292
25

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

Adam Mitz
  • 6,025
  • 1
  • 29
  • 28
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

Nemanja Trifunovic
  • 24,346
  • 3
  • 50
  • 88
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++.

Mike Dimmick
  • 9,662
  • 2
  • 23
  • 48
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

Jason Harrison
  • 922
  • 9
  • 27