# Literal UL

Printable View

• 01-31-2008
shani
Literal UL
Hi
Could anyone please explain what does this literal UL mean? I tried to search on the internet for some article but could not find something.

I guess it means unsigned long, but why is it used?

Thanks
Shani
• 01-31-2008
matsp
If you see something like x = 3UL; yes, that means "unsigned long" [and you can use either separately, e.g, 3U or 3L will mean "unsigned" and "long" respectively].

For most things, it's unnecessary, as the compiler will automatically form whatever type that it thinks is right for the number given, but for example small numeric constants may not be promoted to long when combined with other "small" numbers - for example 1 << 30 may not work right on a 16-bit machine.

--
Mats
• 02-09-2008
shani
Thanks Mats.

Is there some equivalent of UL for unsigned short/signed short?

Shani
• 02-09-2008
Banana Man
Quote:

Is there some equivalent of UL for unsigned short/signed short?
No, you just use a regular constant without any suffix.
• 02-09-2008
dwks
The only suffixes are:
• F after a floating point literal makes that number a float instead of a double.
• L after an integral literal makes that number a long instead of an int.
• U after an inregral literal makes that literal unsigned. This can be combined with L to get an unsigned long, as you have seen.
• C99 and non-standard C++ only: LL makes an integral literal a long long. This can also be combined with U.

As you might have surmised, an ordinary integer literal like "123" is of type int, while an ordinary floating-point literal like "3.14159265358979324" is of type double.

 The reason there are suffixes for longs but not shorts is that a short can be stored in an int, so a short literal can be represented as an int one. You might still get overflow by assigning that int to a short, but that's a different problem. [/edit]

Note that all suffixes are case-insensitive, though many people prefer uppercase because 4l (four ell) looks like 41 (forty one) while 4L is clearly a long 4.

You also get prefixes, for example, 0x makes an integral constant a hexadecimal one, while 0 makes it an octal one . . . I'm not sure if they can be combined or not. It would appear so.
Code:

```\$ cat > combinefix.c #include <stdio.h> int main() {     printf("&#37;lu\n", 0xffUL);     return 0; } \$ gcc -W -Wall -ansi -pedantic -g combinefix.c -o combinefix && ./combinefix 255 \$```