Difference between uint and unsigned int?

后端 未结 5 1546
清歌不尽
清歌不尽 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:07

    All of the answers here fail to mention the real reason for uint.
    It's obviously a typedef of unsigned int, but that doesn't explain its usefulness.

    The real question is,

    Why would someone want to typedef a fundamental type to an abbreviated version?

    To save on typing?
    No, they did it out of necessity.

    Consider the C language; a language that does not have templates.
    How would you go about stamping out your own vector that can hold any type?

    You could do something with void pointers,
    but a closer emulation of templates would have you resorting to macros.

    So you would define your template vector:

    #define define_vector(type) \
      typedef struct vector_##type { \
        impl \
      };
    

    Declare your types:

    define_vector(int)
    define_vector(float)
    define_vector(unsigned int)
    

    And upon generation, realize that the types ought to be a single token:

    typedef struct vector_int { impl };
    typedef struct vector_float { impl };
    typedef struct vector_unsigned int { impl };
    

提交回复
热议问题