Uint32, int16, uint8 .. Why these commonly used data types are not part of the standards

Over the years, across several organizations and various C / C ++ related projects, I have seen that the need for fixed width integers has been addressed by defining a local version types.h

that will look something like this: -

typedef  signed char        int8;
typedef  unsigned char      uint8;
typedef  signed short       int16;
typedef  unsigned short     uint16;
typedef  signed long        int32;
typedef  unsigned long      uint32
typedef  signed long long   int64;
typedef  unsigned long long uint64;

      

Why don't they integrate into C / C ++ standards?

I know I have C99

standardized similar ones uint32_t

. Likewise, Microsoft has defined its own UINT32

, etc. - But this is still required typedef

as the use of uingX lingo is widespread among legacy as well as new code written by experienced developers.

I also know Boost Integer Library - Again, that's not standard C ++ as they clearly state: -

Since they are header headers, their names follow the boost header of the naming convention, not the C ++ standard library library naming convention.

Thoughts on the pros versus integration [u]intX

into official standards?

EDIT : The
question has already provided quality answers and opinions. Thank you, they are informative and helpful !! Some comments suggest that the question is not clear enough: -
"you are asking specifically about adding additional aliases for already existing typedefs in the standard" - yes for sure

@Pascal Cuoq ans solves the real problem if they are added to standards: -

Don't wait for the name to UINT32

become the official name of an integer type in C ++; this will probably never happen, precisely because this is why many programs already type this name .

+3


source to share


3 answers


C99 introduced the header stdint.h

(7.18) and C ++ 11 imported it as <cstdint>

.

You may be asking why the type names are there uint32_t

instead uint32

. Simple: because then the names would collide with the existing code.

POSIX reserved a suffix _t

for types. (You shouldn't use _t

for any type of your program if you want to be POSIX compatible with current and future POSIX systems. This is a common mistake even experienced programmers make). POSIX also used a reserved namespace to safely define type names in uint32_t

.



C99 chose the same names as POSIX. From the point of view of the C committee, it is unlikely that these names will break existing programs (backward compatibility is a very important consideration when designing a C language). Later, when they appeared in C ++, there was more value in maintaining compatibility between C ++ and C than in choosing different names.

Don't wait for the name to uint32

become the official name of an integer type in C ++; this will probably never happen, precisely because so many programs are already typedef

typing this name.

+8


source


They are actually part of the C ++ 11 standard, but with the suffix _t

:

http://en.cppreference.com/w/cpp/types/integer

do not deviate from other common types and adhere to a naming scheme . It would be very controversial to have some standard types ending in _t

and some not.

However, some of them are optional as the underlying hardware may not support them. And thus, there are some analogs, such as those int_least8_t

that are at least 8 bits in size:



smallest signed integer type with a width of at least 8 bits

this type, in turn, can guarantee portability.

You cannot / should not put things in a standard that is not portable, which prohibits the use of the language on a particular platform.

How long does the code break? In addition to the top insights I read in previous C ++ standards committee meetings: when a new function is introduced, a reference implementation will be executed, and compilation tests run on existing code to see how much code that function might break. For example, this happened when the value of a keyword changed auto

.

+4


source


typedefs with suffixes have _t

existed as part of another official standard since the late 90s, perhaps earlier, which is why the versions that went into the C and C ++ standards.

People using different typedefs when standard typedefs already exist is their problem. Duplicating the entire list of typedefs in the standard just creates a big problem.

+3


source







All Articles