Motivation for using size_t uint32 uint64 etc

前端 未结 5 1542
南旧
南旧 2021-02-20 05:37

When I reading some code, for integer, they use bunch of different type such as size_t, uint32, uint64 etc. What is the motivation or purpose to do this? Why not ju

5条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-20 06:01

    For most day-to-day programming, the size of an integer doesn't really matter all that much. But sometimes it is good to be specific. This is especially useful in low-level or embedded programming. Another place it is useful is scientific or computationally intensive tasks where it might be wasteful to use an int that is bigger than necessary.

    The advantage of size_t is that it is unsigned. On the one hand it nice to use size_t because it adds more information about what the argument should be (i.e not negitave). On the other hand it is less tying vs. unsigned int.

提交回复
热议问题