Difference between uint and unsigned int?

后端 未结 5 1448
清歌不尽
清歌不尽 2021-02-01 00:23

Is there any difference between uint and unsigned int? I\'m looking in the site, but all question refers to C# or C++. I\'d like to have an answer conc

5条回答
  •  孤独总比滥情好
    2021-02-01 01:02

    I am extending a bit answers by Erik, Teoman Soygul and taskinoor

    uint is not a standard.

    Hence using your own shorthand like this is discouraged:

    typedef unsigned int uint;

    If you look for platform specificity instead (e.g. you need to specify the number of bits your int occupy), including stdint.h:

    #include 
    

    will expose the following standard categories of integers:

    • Integer types having certain exact widths

    • Integer types having at least certain specified widths

    • Fastest integer types having at least certain specified widths

    • Integer types wide enough to hold pointers to objects

    • Integer types having greatest width

    For instance,

    Exact-width integer types

    The typedef name int N _t designates a signed integer type with width N, no padding bits, and a two's-complement representation. Thus, int8_t denotes a signed integer type with a width of exactly 8 bits.

    The typedef name uint N _t designates an unsigned integer type with width N. Thus, uint24_t denotes an unsigned integer type with a width of exactly 24 bits.

    defines

    int8_t
    int16_t
    int32_t
    uint8_t
    uint16_t
    uint32_t
    

提交回复
热议问题