Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ULL suffix on a numeric literal

Tags:

c++

c

I've run across some code like this:

line += addr & 0x3fULL; 

Obviously, 'U' and 'L' are not hex digits. I'm guessing that the 'ULL' at the end of that hex numeric literal means "Unsigned Long Long" - am I correct? (this sort of thing is very difficult to google) if so then this is some sort of suffix modifier on the number?

like image 879
aneccodeal Avatar asked Jan 10 '12 19:01

aneccodeal


People also ask

What does ULL in C mean?

unsigned long int: character ul or UL at the end of integer constant. long long int: character ll or LL at the end of integer constant. unsigned long long int: character ull or ULL at the end of integer constant.

What are the types of integer literal?

They can be represented as: Decimal integer literals. Hexadecimal integer literals. Octal integer literals.

What is the value of integer literal 013?

It is extremely easy to inadvertently create an integer object with the wrong value, because '013' means 'decimal 11', not 'decimal 13', to the Python language itself, which is not the meaning that most humans would assign to this literal.


2 Answers

From the gcc manual:

ISO C99 supports data types for integers that are at least 64 bits wide ( . . . ) . To make an integer constant of type long long int, add the suffix LL to the integer. To make an integer constant of type unsigned long long int, add the suffix ULL to the integer.

These suffixes have also been added to C++ in C++11, and were already supported long long (pun intended) before that as compiler extensions.

like image 56
NPE Avatar answered Sep 16 '22 19:09

NPE


Yes that's correct.

  • 0x prefix makes it a hexadecimal literal.
  • ULL suffix makes it type unsigned long long.
like image 21
Mysticial Avatar answered Sep 18 '22 19:09

Mysticial