what is the difference between uint16_t and unsigned short int incase of 64 bit processor?

前端 未结 2 1554
半阙折子戏
半阙折子戏 2021-01-31 16:17

I came to use a variable of type uint16_t, but am unable to use that data type because of my project limitations. Is it possible to unsigned short int

2条回答
  •  伪装坚强ぢ
    2021-01-31 17:01

    uint16_t is unsigned 16-bit integer.

    unsigned short int is unsigned short integer, but the size is implementation dependent. The standard only says it's at least 16-bit (i.e, minimum value of UINT_MAX is 65535). In practice, it usually is 16-bit, but you can't take that as guaranteed.

    Note:

    1. If you want a portable unsigned 16-bit integer, use uint16_t.
    2. inttypes.h and stdint.h are both introduced in C99. If you are using C89, define your own type.
    3. uint16_t may not be provided in certain implementation(See reference below), but unsigned short int is always available.

    Reference: C11(ISO/IEC 9899:201x) §7.20 Integer types

    For each type described herein that the implementation provides) shall declare that typedef name and define the associated macros. Conversely, for each type described herein that the implementation does not provide, shall not declare that typedef name nor shall it define the associated macros. An implementation shall provide those types described as ‘‘required’’, but need not provide any of the others (described as ‘optional’’).

提交回复
热议问题