2

The suffix l and L for numeric literals long int and long double are the same. I don't understand how the compiler can know if I want my numeric literal to be a long int or a long double if they both share the same suffix. Why does this work?

I know I'm missing something completely obvious here.

Wandering Fool
  • 2,170
  • 3
  • 18
  • 48
  • See also the related questions: [Purpose of a “.f” appended to a number?](http://stackoverflow.com/q/4828167/96780), [Why isn't “0f” treated as a floating point literal in C++?](http://stackoverflow.com/q/3961467/96780) – Daniel Daranas May 19 '15 at 14:44
  • Thanks for the first link. I was messing around with trying to append an f suffix to an integer literal on my compiler and it was giving me syntax errors. This explains it well. – Wandering Fool May 19 '15 at 14:52

2 Answers2

3

A literal number needs to have a period or an exponent to be treated as a floating point literal constant. If it doesn't have any of these, it is treated as an integer literal constant.

Daniel Daranas
  • 22,454
  • 9
  • 63
  • 116
0

From C11 6.4.4.2/4:

An unsuffixed floating constant has type double. If suffixed by the letter f or F, it has type float. If suffixed by the letter l or L, it has type long double.

A floating constant is defined by the grammar at the start of 6.4.4.2. It must either contain . , so there is no ambiguity with integer constants which may not contain that.

M.M
  • 138,810
  • 21
  • 208
  • 365