[ACCEPTED]-Uint32", "int16" and the like; are they standard c++?-c++

Accepted answer
Score: 19

Unix platforms define these types in stdint.h, this 8 is the preferred method of ensuring type 7 sizing when writing portable code.

Microsoft's 6 platforms do not define this header, which 5 is a problem when going cross-platform. If 4 you're not using Boost Integer Library already, I recommend getting 3 Paul Hsieh's portable stdint.h implementation of this header 2 for use on Microsoft platforms.

Update: Visual 1 Studio 2010 and later do define this header.

Score: 13

The C99 header file stdint.h defines typedefs 15 of this nature of the form uint32_t. As far as I 14 know, standard C++ doesn't provide a cstdint 13 version of this with the symbols in namespace 12 std, but some compilers may, and you will 11 typically be able to include the C99 header 10 from C++ code anyways. The next version 9 of C++ will provide the cstdint header.

You 8 will often see code from other people who 7 use non-standard forms of this theme, such 6 as Uint32_t or Uint32 or uint32 etc. They typically just provide 5 a single header that defines these types 4 within the project. Probably this code was 3 originally developed a long time ago, and 2 they never bothered to sed replace the definitions 1 out when C99 compilers became common.

Score: 12

Visual c++ doesn't support the fixed-width 4 integer types, because it doesn't include 3 support for C99. Check out the answers to 2 my question on this subject for various options you have for using 1 them.

Score: 3

The main reason for using them is that you 6 then don't have to worry about any possible 5 problems arising when switching between 4 64bit and 32bit OS.

Also if you are interfacing 3 to any legacy code that you new was destined 2 for 32bit or even 16bit then it avoids potential 1 problems there as well.

Score: 1

Try UINT32 for Microsoft.

The upper case 5 makes it clear that this is defined as a 4 macro. If you try to compile using a different 3 compiler that doesn't already contain the 2 macro, you can define it yourself and your 1 code doesn't have to change.

Score: 1

uint32 et al. are defined by macros. They solve 6 a historic portability problem of there 5 being few guarantees across platforms (back 4 when there there more platform options than 3 now) of how many bits you'd get when you 2 asked for an int or a short. (One now-defunct 1 C compile for the Mac provided 8-bit shorts!).

More Related questions