C interpretation of hexadecimal long integer literal “L”

不羁岁月 提交于 2019-12-02 04:02:19

It's a hexadecimal literal, so its type can be unsigned. It fits in unsigned long, so that's the type it gets. See section 6.4.4.1 of the standard:

The type of an integer constant is the first of the corresponding list in which its value can be represented.

where the list for hexadecimal literals with a suffix L is

  1. long
  2. unsigned long
  3. long long
  4. unsigned long long

Since it doesn't fit in a 32-bit signed long, but an unsigned 32-bit unsigned long, that's what it becomes.

The thing is that the rules of determining the type of the integral literal are different depending on whether you have a decimal number or a hexadecimal(or octal number). A decimal literal is always signed unless postfixes with U. A hexadecimal or octal literal can also be unsigned if the signed type can not contain the value.

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