How to input int64_t / uint64_t constants?

后端 未结 3 1041
滥情空心
滥情空心 2020-12-11 02:24

What I\'m trying to do is to define a constant equal to 2^30 (I may change it to something like 2^34, so I prefer to have a room larger than 32 bits for it).

Why the

3条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-11 02:38

    (uint64_t 1) is not valid syntax. When casting, you can either use uint64_t(1) or (uint64_t) 1. The commented out example works because it follows the proper syntax for casting, as would:

    const uint64_t test = ((uint64_t)1) << 30;
    

    Edit: While this directly answers the question, see the answer by Shafik Yaghmour on how to properly define an integral constant with specific size.

提交回复
热议问题