Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Can you use C++14s single quote (') digit separator with non-integer types?

According to https://en.cppreference.com/w/cpp/language/integer_literal C++14 allows the single quote separator in integer types to help with readability:

Optional single quotes(‘) may be inserted between the digits as a separator. They are ignored by the compiler. [since C++14]

However, my question is whether it is safe to use it for floating point numbers too? The following code compiles without warnings for me, however, I’m concerned whether any implicit casting is happening due to the separator in the float:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

int main()
{
    int foo = 1'000;
    float bar = 1'000.f;
}

>Solution :

Yes they are allowed. Looking at the floating-point literal page we have the same quote

Optional single quotes (‘) may be inserted between the digits as a separator; they are ignored during compilation. (since C++14)

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading