Jump to content
  • Advertisement
Sign in to follow this  
GenuineXP

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

This topic is 3549 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Boost actually offer a TR1 implementation (everything placed in the std::tr1 namespace), so you could use that.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!