Home > Software engineering >  What does integer-class type mean in C since integer is a built in type
What does integer-class type mean in C since integer is a built in type

Time:04-18

While reading through the documentation of std::numeric_limits i came across the following statement:

Specializations for all integer-class types are also provided. (since C 20)

My question is that what do we mean by integer class types in the above statement. I mean i know that int is a built in type in C . And we can provide user-defined class in C . But i never read about an integer-class type. I tried searching that phrase on google, but didn't find anything related to this.

CodePudding user response:

From the history we can see that this pertains to the iterator concepts added in C 20; in particular, [iterator.concept.winc]/2 says

A type I is an integer-class type if it is in a set of implementation-defined types that behave as integer types do, as defined below.

[Note 1: An integer-class type is not necessarily a class type. — end note]

The library is given permission to use one of these suitably integer-like types to represent the sizes of ranges and the distances between elements of ranges.

CodePudding user response:

It's yet another set of integer types, that are neither standard integer types nor extended integer types.

There are five standard signed integer types: “signed char”, “short int”, “int”, “long int”, and “long long int”. In this list, each type provides at least as much storage as those preceding it in the list. There may also be implementation-defined extended signed integer types. The standard and extended signed integer types are collectively called signed integer types.

A problem here is that the typedef intmax_t must be defined as the largest of these integer types (thus its name :-).

Now if an implementation were to define a new set of "integer-class types" that are not "standard" or "extended" integers, but merely "integer-like", it could use those types without changing intmax_t.

Saves us from an ABI break for all previous uses of intmax_t parameters.

  • Related