'Why cannot you use a 'f' suffix directly after an integer?

While writing a C++ application, I have found out that I cannot use the f suffix(e.g. 3f) as Visual Studio shows me the following error: "Literal operator not found". The problem, of course, disappears when I use the .f suffix(e.g. 3.f). Why is that?



Solution 1:[1]

Why cannot you use a 'f' literal directly after an integer?

If f suffix was allowed after text forming an integer to become a floating point, a problem would occur with hexadecimal integers/floating-point

0x1.23f  // this is a float
0x1p23f  // this is a float
0x123f   // If this now a float?  No, it remains an integer.

The f suffix changes the type of a floating point literal from the default of double. In C, an f or F suffix does not make a floating point literal but a floating point constant.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1