Why size_t when int would suffice for the size of an array?

后端 未结 5 1875
[愿得一人]
[愿得一人] 2021-01-17 13:09

The C standard guarantees that an int is able to store every possible array size. At least, that\'s what I understand from reading §6.5.2.1, subsection 1 (Array

5条回答
  •  滥情空心
    2021-01-17 13:51

    integer type is not necessarily an "int". "long long" is an integer type too, as is "size_t".

    Arrays can be larger than 2GB. This property is quite handy for those who write memory hungry programs, e.g DBMS with big buffer pools, application servers with big memory caches etc. Arrays bigger than 2GB/4GB is the whole point of 64 bit computing :)

    size_t for strlen(), at least sounds compatible with how C standard handles arrays, whether it makes practical sense or not, or whether somebody have seen strings that large, is another question.

提交回复
热议问题