Kinda newbie C++ question... (warnings)
by Alessandro Loureiro · in Torque Game Engine · 04/25/2005 (8:10 am) · 8 replies
Hello. I happen to be a prfeccionist, and I'd really like my torque engine to compile without all those nasty warnings, even because, then if I see warnings while compilations, I can be sure they'll be related to what *I* did with the code. But thing is, I don't have enough experience with C++ to get rid of all those typecasting erros and other stuff, I never worked on a code so big. and so, I'd like some hints on what I should to to fix them... for an example, these errors:
and all similar mistakes... I know this isn't crucial and that the engine compiles and works fine, but I'd really like to get rid of those warnings, can somebody help me out here? thanks in advance :)
Quote:
"argument to 'int' from 'float'" in audio.cc line 161
"passing 'F32' for argument 1 of 'void'" in audiodatablock.cc line 376
"initialization to 'ogg_int64_t' from '" in vorbisstream.cc line 1255
"assignment to non-pointer type 'ALuint'" in wavStreamSource.cc line 109
"argument of negative value '-1' to 'unsigned int" in aiPlayer.cc line 377
"[i]'dllglAccum' initialized and declared" in GLCoreFunc.h line 7
and all similar mistakes... I know this isn't crucial and that the engine compiles and works fine, but I'd really like to get rid of those warnings, can somebody help me out here? thanks in advance :)
#2
And by the way, the correct spelling is "grammar".
04/25/2005 (2:36 pm)
Thanks for the answer, Chris, but I must say that english is not my native language, I'm from Brazil, and, altough my grammar isn't "perfect" as you say, it is pretty good taking into account that I learned english all by myself.And by the way, the correct spelling is "grammar".
#3
Most of those can simply be fixed by doing a C-Style cast to force the variable to its new type : to go from float to int, just put an (int) in front of the float being demoted to int. You don't need it the other way (int to float) as C/C++ automatically does that type promotion.
Another source for a lot of those errors is that floating point constants in TGE are not suffixed with an f (eg. 5.7f), which makes them double by default, which then leads to the double to float truncation warnings.
They're annoying but can be ignored for the most part :)
Changing the warning level back to the default used by the visual studio project files will also make them disappear, but obviously that's not the solution for you, since you changed it to a higher warning level :)
Have fun
04/25/2005 (2:50 pm)
Alessandro, if you want to get rid of those warnings for real, you're going to have to go look at the code for each of them. Most of those can simply be fixed by doing a C-Style cast to force the variable to its new type : to go from float to int, just put an (int) in front of the float being demoted to int. You don't need it the other way (int to float) as C/C++ automatically does that type promotion.
Another source for a lot of those errors is that floating point constants in TGE are not suffixed with an f (eg. 5.7f), which makes them double by default, which then leads to the double to float truncation warnings.
They're annoying but can be ignored for the most part :)
Changing the warning level back to the default used by the visual studio project files will also make them disappear, but obviously that's not the solution for you, since you changed it to a higher warning level :)
Have fun
#4
Either way, your issue is simply due to casting from one data type to another as was stated above, if you wish to fix all of these please feel free to do so and submit a patch for the rest of us to enjoy! :)
Otherwise don't worry too much about misteaks :)
04/25/2005 (2:54 pm)
@Alessandro, Potato, Potatoe, welcome to Amerika! We have more flexible grammar rules here than most english speaking countries seeing as how, we are a melting pot of different cultures and languages, the english lexicon has been the primary benefactor of this, unfortunately in the process, proper english syntax has been torn to shreds.Either way, your issue is simply due to casting from one data type to another as was stated above, if you wish to fix all of these please feel free to do so and submit a patch for the rest of us to enjoy! :)
Otherwise don't worry too much about misteaks :)
#5
so, I should add a line to type-cast the mScore value before the line in bold? thanks a lot man, that really helped me clarify things. I guess GG wasn't lying when I read about how friendly and helpful the community is :)
oh, and Dreamer, thank you for the kind answer :)
EDIT: but I was thinking... if you demote a value from float to int, wouldn't that round the value down to the previous integer?
04/25/2005 (2:57 pm)
Aah, I see... I was a little afraid to go experimenting without knowing what I'm doing on that matter because almost all warnings are being issued by pointers, not direct values. for an example, the first warning on my list (which has been pasted from my console output) refers to this function over here:inline int QSORT_CALLBACK loopingImageSort(const void * p1, const void * p2) {
const LoopingImage * ip1 = *(const LoopingImage**)p1;
const LoopingImage * ip2 = *(const LoopingImage**)p2;
// min->max
[b]return ip2->mScore - ip1->mScore;[/b]
}so, I should add a line to type-cast the mScore value before the line in bold? thanks a lot man, that really helped me clarify things. I guess GG wasn't lying when I read about how friendly and helpful the community is :)
oh, and Dreamer, thank you for the kind answer :)
EDIT: but I was thinking... if you demote a value from float to int, wouldn't that round the value down to the previous integer?
#6
04/25/2005 (3:16 pm)
Yes it would, but if it's happening anyways, you may as well cleanup the errors from doing so.
#7
audio/audio.cc:166: warning: invalid conversion from 'float (*)(const void*, const void*)' to 'int (*)(const void*, const void*)'
now I'm really confused...
04/25/2005 (3:36 pm)
OK, tell me if I'm wrong, but in the case of the function up there, I made it so the function would return a float value instead of an int (mScore is defined as float in the LoopingImage struct, didn't want to mess with that), and it didn't give more errors. HOWEVER, I got a new warning now, in this function:void LoopingList::sort() {
[b]dQsort(address(), size(), sizeof(LoopingImage*), loopingImageSort);[/b]
}audio/audio.cc:166: warning: invalid conversion from 'float (*)(const void*, const void*)' to 'int (*)(const void*, const void*)'
now I'm really confused...
#8
You should go for least intrusive changes, modifying return types is a lot more intrusive than casting the return to its proper type.
04/25/2005 (5:47 pm)
You want to do return (int) (ip2->mScore - ip1->mScore); for that QSORT callback rather than change return types. You should go for least intrusive changes, modifying return types is a lot more intrusive than casting the return to its proper type.
Torque Owner Chris Labombard
Premium Preferred
As for the typecasts, change the severity at which your compiler reports warnings. Then you will only see what your code messes up in the engine.