c++ - Literal constant suffixes when initializing variables -


is practice use suffixes when initializing variables? these cases?

float foo = 0.0f; unsigned int bar = 0u; 

or use literal suffixes when there might conversion problem?

this cpp faq

you should use these suffixes when need force compiler treat numeric literal if specified type

there's example:

if x of type float, expression x + 5.7 of type double: first promotes value of x double, performs arithmetic using double-precision instructions. if want, fine; if wanted arithmetic using single-precision instructions, can change code x + 5.7f.

there readability reasons

if end using unsigned variables, idea force numeric literals unsigned. makes easier see compiler generate “unsigned arithmetic” instructions.


Comments

Popular posts from this blog

IF statement in MySQL trigger -

c++ - What does MSC in "// appease MSC" comments mean? -

android - MPAndroidChart - How to add Annotations or images to the chart -