When to use short instead of int?

前端 未结 5 1653
梦如初夏
梦如初夏 2021-02-08 11:46

Two use cases for which I would consider short come to mind:

  1. I want an integer type that\'s at least 16 bits in size
  2. I want an integer type t
5条回答
  •  情书的邮戳
    2021-02-08 12:09

    Yes, if you really want a particular data size you use int16_t, int32_t, etc.

    int16_t is usually a platform-specific typedef from short (or whatever maps to 16 bits). On a 32-bit machine, int16_t may be typedef'd as short, on a 16-bit machine int16_t may be typedef as int.

提交回复
热议问题