0

What is the meaning of "l" in some variable initialisations? For example:

#define maxpossible     (1000000000L)
double A = 1L;
double B = 999999999l;

Is there a difference between "L" and "l"?

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
Oussa
  • 135
  • 1
  • 10

2 Answers2

5

This is a suffix type specifier, for A and B you can read more about floating point literals here. The short answer is that L and l both indicate long double. For maxpossible you can read about integer literal here and L indicates long.

EDIT

As Mike Seymour kindly pointed out all of the literals are integer literals. This just goes to show that the times when you do not sanity check your answer, you will say something wrong. A simple sanity check would have been as follows:

#include <iostream>
#include <typeinfo>

int main()
{
    std::cout << typeid( decltype( 1L ) ).name() << std::endl ;
    std::cout << typeid( decltype( 999999999l ) ).name() << std::endl ;
    std::cout << typeid( decltype( 1000000000L ) ).name() << std::endl ;
}

Which gives me l for each one and running that through c++filt -t gives me long. What would have made the literals floating point literals? Either a:

  • Digits containing a decimal point
  • Digits with exponential notation, for example 4e2

For example:

std::cout << typeid( decltype( .1l ) ).name() << std::endl ;
std::cout << typeid( decltype( 1e2L ) ).name() << std::endl ;

Which gives me e for both cases and running that through c++filt -t gives me long double.

Shafik Yaghmour
  • 154,301
  • 39
  • 440
  • 740
  • Except that all three literals here are integers. – Mike Seymour May 20 '13 at 08:11
  • @MikeSeymour Now that I have coffee, what is sad is that you were the first one to pick that up. I still have no idea what I thought I saw when I answered(I must have mentally inserted a decimal) but clearly as I updated sanity checking would have caught it and it usually what I do. Thanks for pointing it out. – Shafik Yaghmour May 20 '13 at 13:16
2

since These are literal constants.

The suffix l or L makes the constant be long or long double.

In your example, maxpossible is a long integer. A and B are both long doubles. But since you are declaring them as double, they are stored as doubles.

Ram Rajamony
  • 1,717
  • 15
  • 17