3

Possible Duplicate:
unsigned int vs. size_t

When I need to store the size of something (usually stuff allocated with new), I always store it in an unsigned int. Browsing through some code, however, I saw size_t used. According to this, it's hardly used for a lot.

  • What is the point of size_t in C++?
  • Why don't those few functions that use it just use an unsigned int instead?
  • How should it be used in new code?
Community
  • 1
  • 1
Maxpm
  • 24,113
  • 33
  • 111
  • 170
  • possible duplicate of [unsigned int vs. size_t](http://stackoverflow.com/questions/131803/unsigned-int-vs-size-t) - pretty definitive info there – Steve Townsend Jan 13 '11 at 20:59

1 Answers1

4

You could have an array, the size and indexing of which can exceed the range of an int, as an int is only guaranteed 16bits. The practicality of using size_t is rather low right now but may become more important in the future. On MSVC compiling for 64bit, for example, I could have a class, an instance of which is larger than 4GB. Of course, I expect that in practicality, the CRT won't deal with sizes that large, but the Standard is unconcerned with that.

Puppy
  • 144,682
  • 38
  • 256
  • 465