Literal types: 0x1ull vs 0x1llu

↘锁芯ラ 提交于 2019-12-19 18:55:32

问题


My gcc compiler allows me to define an unsigned long long (i.e. 64-bit) literal as

#define A_LITERAL 0x1ull

--- or ---

#define A_LITERAL 0x1llu

Is there any difference between these two literal statements. Is this common to other C compilers?


回答1:


Both are allowed by the C standard (section 6.4.4.1).

The unsigned suffix u can be before or after the long l (or long long (ll)) suffix.




回答2:


Both are the same: excerpt from n3337 draft of C++11 standard:

integer-suffix:
    unsigned-suffix long-suffix(opt)
    unsigned-suffix long-long-suffix(opt)
    long-suffix unsigned-suffix(opt)
    long-long-suffix unsigned-suffix(opt)

unsigned-suffix: one of
    u U

long-suffix: one of
    l L

long-long-suffix: one of
    ll LL



回答3:


ull or llu force the compiler to treat a constant as an unsigned and long long integer.
The order of ll and u doesn't matter, nor their case. you may also write LLU or ULL.



来源:https://stackoverflow.com/questions/17287680/literal-types-0x1ull-vs-0x1llu

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!