How to partially disable C4244

In Visual C ++ 2012, the code

double d = 0.5; float f = d; int i = f; 

gives 2 warnings for me:

 test.cpp(26): warning C4244: 'initializing' : conversion from 'double' to 'float', possible loss of data test.cpp(27): warning C4244: 'initializing' : conversion from 'float' to 'int', possible loss of data 

I want to suppress the first warning, which I consider to be spam, but keep the second warning, which I find very useful. Is it possible to suppress one and save the other? Do people generally just crush them all? We had a bad mistake, in which we mistakenly transmitted a double melt. But we, tons of our math code, will trigger double swimming warnings.

+6
source share
1 answer

Do not suppress warnings designed to prevent possible errors. Tell the compiler that you know what you are doing, instead:

 double d = 0.5; float f = static_cast<float>(d); int i = static_cast<int>(f); 
+5
source

Source: https://habr.com/ru/post/957721/


All Articles