c++ - What data type should I use for a general purpose integer? -
What data types should be used for general-purpose integer in C ++?
The obvious answer is int
, and it was understood in the old time, where it was 16-bit on 16-bit machines and 32-bit was on 32-bit machines . But now the 64-bit code is getting more common, but int
is often 32-bit on those compilers, so we can not assume that int
is necessary for that system's The "fastest" or biggest type for
Another problem is the spread of 64-bit values by the size of the data. Structures and files I know that you can store these values in 32-bit int and participate with it, if The size does not get very big but I want to write code which can handle the maximum size of the data, if that user wants what I do not want my code to die, if the user opens the 5 GB file and in memory Uri wants something, because size than is stored in a int
16 + GB of RAM system will stop someday, and I still want your code to work.
I know that vector & lt; T & gt; :: size_type
Store that data but what if size data can come from many different containers and stream types? Can I use the size_t
for all information which can store size information?
So I have to conclude that I can live with the code type (or equivalent), I can now live with a maximum of 9,223,372,036,854,775,807 bytes per data structure), and general purpose No for the general purpose calculations, which integer data type Should use and to do so Niki What are the reasons? Depending on a situation, you use different integers generally, two big squares Are integers - they are related to your data model (i.e. domain data), and these are related to the creation of the program. Entries from the program's domain (such as user data, data that collects or calculates your program, and so on) must be presented with specific shaping types. These types are defined in C ++. For example, if you need a signed 32-bit type that is portable in all platforms, use If you are related to the speed of execution, use the integer type with An integer related to the program structure is created when you take the size of the data structures or decrease the points. int
for use, but this is not how I see in practice, where
int32_t
; If you want a 64-bit unsigned number, use uint64_t
, and so on. fastN_t
suffix, e.g. fastest 16-bit signed integer uint_fast16_t
.
Comments
Post a Comment