30

I have this constant:

#define MAX_DATE  2958465L

What does the L mean in this sense?

Rob Kennedy
  • 159,194
  • 20
  • 270
  • 458
Tony The Lion
  • 59,704
  • 62
  • 233
  • 403

4 Answers4

43

It is a long integer literal.

Integer literals have a type of int by default; the L suffix gives it a type of long (Note that if the value cannot be represented by an int, then the literal will have a type of long even without the suffix).

James McNellis
  • 338,529
  • 73
  • 897
  • 968
  • Sure? AFAIK literals without the 'L' suffix are of integer type in C++, and it will fail to compile if the literal will not fit in the int type. – David Rodríguez - dribeas Jun 02 '10 at 13:29
  • 9
    @David: "If it is decimal and has no suffix, it has the first of these types in which its value can be represented: `int`, `long int` (C++03 §2.13.1/2). – James McNellis Jun 02 '10 at 13:44
  • So it seems like compiler can choose for us automatically. When do we want to put in the `L` suffix ourselves? – kizzx2 Feb 22 '11 at 03:12
  • 6
    @kizzx2: `42` is an `int`. If you want it to be a `long`, you need to add the `L` (giving `42L`). There are many reasons that you might want a `long` explicitly: you might do it to select a particular function overload or to ensure a template is instantiated with `long` instead of `int`. You might use it to ensure some integer expression is evaluated with `long` precision instead of `int` precision. `INT_MAX + 1` will overflow. If `long` has greater range than `int`, `INT_MAX + 1L` will not overflow. – James McNellis Feb 22 '11 at 03:30
8

In this scenario the Ldoes nothing.

The L after a number gives the constant the long type, but because in this scenario the constant is immediately assigned to an int variable nothing is changed.

orlp
  • 106,415
  • 33
  • 201
  • 300
3

L tells the compiler that the number is of type Long. Long is a signed type greater than or equal to an int in size. On most modern compilers, this means that the number will take 4 bytes of memory. This happens to be the same as an int on most compilers so it won't have an effect in this case.

Steve Rowe
  • 19,315
  • 9
  • 50
  • 81
0

see this link it says :

Literal constants (often referred to as literals or constants) are invariants whose values are implied by their representations.

base:decimal

example:1L

description: Any decimal number (digits 0-9) not beginning with a 0 (zero) and followed by L or l

Pau Coma Ramirez
  • 3,351
  • 1
  • 17
  • 19
Vijay
  • 62,703
  • 87
  • 215
  • 314