Adding stdint.h to Visual Studio

On November 13, 2011, in Code Monkey, by Tom

Yes, stdint.h and inttypes.h are missing from Microsoft Visual Studio. As a result, anyone who’s written cross-platform C\C++ code for Windows has probably seen this error:

error C2146: syntax error : missing ';' before identifier 'foo'
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

The fact is that Visual Studio doesn’t implement C99… it implements C89 (for compatibility reasons). So, you don’t have access to familiar types like:

  • int8_t, int16_t, int32_t, int64_t
  • uint8_t, uint16_t, uint32_t, uint64_t
  • INT8_MIN, INT8_MAX, etc
  • The fprintf macros PRId32, PRIu32, etc
  • strtoimax(), etc

Fortunately, Alexander Chemeris has written msinttypes: an implementation of stdint.h and inttypes.h for Microsoft Visual Studio. It is licensed under the BSD license, so the headers are actually usable commercially (no viral GPL). This following quote probably goes without saying (emphasis mine):

Note though, that just adding these headers does not make Visual Studio compiler fully C99 compliant.

This project has saved me a bunch of unwanted coding. Thanks Alex!

Tagged with:  

One Response to Adding stdint.h to Visual Studio

  1. Bruce says:

    Visual Studio 2010 has stdint.h in C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>