Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Capturing and Editing Video > Avisynth Development
Register FAQ Calendar Today's Posts Search

Reply
 
Thread Tools Search this Thread Display Modes
Old 4th February 2022, 00:08   #1  |  Link
Reel.Deel
Registered User
 
Join Date: Mar 2012
Location: Texas
Posts: 1,666
Newbie questions regarding warnings and errors when compiling x64 plugins.

Hello all,

I'm creating this thread in hopes of asking some newbie questions when compiling existing plugins in x64. There's still some plugins that are x86 only (and not written in assembly). I'm hoping to compile what I can and put it up on the wiki so that they're available to everyone. I've compiled a few plugins already for personal use, and they all work but sometimes I get some warnings and/or errors that I do not know how to fix.

For example ChannelMixer, it compiles and works but it shows 19 warnings in MSVC 2019.

warning C4244: '=': conversion from 'double' to 'int', possible loss of data (9 WARNINGS)

Code:
	// Build look-up tables
	for(i = 0; i < 256; i++) {
		RR[i] = 0.01 * inRR * (float)i;
		RG[i] = 0.01 * inRG * (float)i;
		RB[i] = 0.01 * inRB * (float)i;

		GR[i] = 0.01 * inGR * (float)i;
		GG[i] = 0.01 * inGG * (float)i;
		GB[i] = 0.01 * inGB * (float)i;

		BR[i] = 0.01 * inBR * (float)i;
		BG[i] = 0.01 * inBG * (float)i;
		BB[i] = 0.01 * inBB * (float)i;
warning C4101: 'tmp': unreferenced local variable (1 WARNING)
Code:
	int i, tmp;
warning C4244: 'argument': conversion from 'double' to 'float', possible loss of data (9 WARNINGS)

Code:
	// Calls the constructor with the arguments provied.
	return new ChannelMixer(args[0].AsClip(), args[1].AsFloat(), args[2].AsFloat(), args[3].AsFloat(), args[4].AsFloat(), args[5].AsFloat(), args[6].AsFloat(), args[7].AsFloat(), args[8].AsFloat(), args[9].AsFloat(), env);
What is the proper way to get rid of these warnings? Also I read sometime ago that some warnings are harmless, is that the case here since the plugin works as intended?

Last edited by Reel.Deel; 4th February 2022 at 08:26. Reason: wrong warning in 1st example
Reel.Deel is offline   Reply With Quote
Old 4th February 2022, 01:35   #2  |  Link
wonkey_monkey
Formerly davidh*****
 
wonkey_monkey's Avatar
 
Join Date: Jan 2004
Posts: 2,496
Quote:
warning C4244: 'argument': conversion from 'double' to 'float', possible loss of data (9 WARNINGS)
There are two types of floating point number, 32-bit floats or 64-bit doubles. If you try to set a float variable to a double value, you'll get this warning.

If any of the variables involved are double, then the whole result gets "upgraded" to a double. In this case, the literal "0.01" is treated as a double. You can force it to a float with an f suffix:

Code:
		RR[i] = 0.01f * inRR * (float)i;
Or you just cast the whole thing to a float (casting only the integer i to a float is somewhat redundant anyway);

Code:
		RR[i] = (float)(0.01 * inRR * i);
It's possible that these two methods will give very slightly different results, or possibly run at very slightly different speeds, since the calculations are done with different accuracies depending on the types involved.

Generally speaking though, this warning is safe to ignore.

Quote:
warning C4101: 'tmp': unreferenced local variable (1 WARNING)
This one's probably just a forgetful/lazy developer. Just remove tmp and it should be fine.

Quote:
warning C4244: 'argument': conversion from 'double' to 'float', possible loss of data (9 WARNINGS)
Avisynth's AsFloat() actually returns a double, which is then being forced to convert to float because ChannelMixer::ChannelMixer(...) is expecting floats. Change all the instances of AsFloat() to AsFloatf() which will return a float instead.
__________________
My AviSynth filters / I'm the Doctor
wonkey_monkey is offline   Reply With Quote
Old 4th February 2022, 07:59   #3  |  Link
Reel.Deel
Registered User
 
Join Date: Mar 2012
Location: Texas
Posts: 1,666
Thanks for the information wonkey_monkey. Removing tmp and changing AsFloat() to AsFloatf() took care of those warnings.

I messed up and copied the wrong warning for the first example, my bad.
The warning is warning C4244: '=': conversion from 'double' to 'int', possible loss of data instead of what I wrote in the 1st post.
I tried both of your suggestions and I still get the same warning.
Reel.Deel is offline   Reply With Quote
Old 4th February 2022, 08:37   #4  |  Link
DTL
Registered User
 
Join Date: Jul 2018
Posts: 1,075
It looks the computation
0.01 * inRR * (float)i;
is in double because 0.01 is defined as double and compiler raises precision to highest used component in formula.

And RR[i] possibly int. So compiler warn - conversion of double formula calculation result to int output memory value.

So to fix warning - make explicit conversion of computation result to int:

RR[i] = (int)(0.01f * inRR * (float)i);

Also use 0.01 as float32 that may make computing faster. I hope float32 is enough in that use case.
DTL is offline   Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:30.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.