stdint.h, cstdint, and cstdint.hpp, oh my!

Started by
3 comments, last by dmatter 15 years, 4 months ago
I'm wondering if the use of the standard C header stdint.h is okay in C++ code. TR1 seems to offer a cstdint header, but I'm actually interfacing C and C++ code and it seems it would be simpler to forgo differentiating the two headers. I also prefer that these types be defined at global scope. Besides, my TR1 header just includes the stdint.h C header anyway (like many C library headers for C++) and pulls the types into the std::tr1 namespace. Why wasn't this header a part of C++ from the start (i.e., ever since C had the header)? Also, what exactly is the point of Boost's cstdint.hpp header then? Is it more reliable/portable (for example, if you can't be sure TR1 will be available)? When should I prefer Boost's header over the TR1 or C header? Any input is appreciated. Sometimes I wish specifically sized integer types were actually a part of the language.
Advertisement
Some compilers, such as MSVC, don't ship with the standard stdint header.
NextWar: The Quest for Earth available now for Windows Phone 7.
C was first standardized in 1989, but stdint.h was not part of C89. C++ was first standardized in 1998. Since stdint.h was not part of C at the time, C++ did not create a cstdint header. The next version of the C standard, was standardized in 1999, which added the stdint.h header. Boost found this to be useful functionality, so encapsulated it in cstdint.hpp. This was then accepted as useful functionality by the standards committee, so now you actually have cstdint on compilers that support it, and should be in all compilers that support C++0x when it is finished.
Ah. I didn't realize that stdint.h was not a part of C89. It makes more sense to me now.

Which should I prefer though? I'd like for my code to be reasonably portable, so should I prefer Boost's header or TR1's header? It seems to me that getting your hands on Boost is easier than grabbing a TR1 implementation if you don't already have it, but I'm not sure.

Thanks for the information.
Boost actually offer a TR1 implementation (everything placed in the std::tr1 namespace), so you could use that.

This topic is closed to new replies.

Advertisement