Which initializer is appropriate for an int64_t?

后端 未结 3 1895
梦谈多话
梦谈多话 2020-12-09 18:33

I like to initialize my variables to some \"dummy\" value and have started to use int64_t and uint64_t. So far, it looks like there are at least th

3条回答
  •  粉色の甜心
    2020-12-09 18:54

    According to the ANSI C standard, the suffix for a long long int and unsigned long long int is LL and ULL respectively:

    octal or hexadecimal suffixed by ll or LL long long int, unsigned long long int decimal, octal, or hexadecimal suffixed by both u or U, and ll or LL unsigned long long int

    If you know that int64_t is defined as:

    typedef signed long long int int64_t
    

    Then method two is most definitely the correct one:

    int64_t method_two   = 0LL;
    uint64_t method_two   = 0ULL;
    

    Edit:

    Keeping in mind the portability issues, and the fact that it's not guaranteed to be defined as long long, then it would be better to use the third method:

    INT64_C()
    UINT64_C()
    

提交回复
热议问题