(minor) Warnings for lrint when compiling in Xcode for iOS
First: thanks to Erik and everyone else here for making and maintaining libsamplerate!
This is just a minor issue (I think):
I'm seeing several warnings in Xcode when compiling for iOS arm64 in Xcode (15.3):
Compiling src_sinc.c
/Users/.....snip...../libsamplerate/src/common.h:221:9: implicit conversion loses integer precision: 'long' to 'int' [-Wshorten-64-to-32]
return lrintf (x) ;
/Users/.....snip...../libsamplerate/src/common.h:226:9: implicit conversion loses integer precision: 'long' to 'int' [-Wshorten-64-to-32]
return lrint (x) ;
Compiling src_zoh.c
/Users/.....snip...../libsamplerate/src/common.h:221:9: implicit conversion loses integer precision: 'long' to 'int' [-Wshorten-64-to-32]
return lrintf (x) ;
/Users/.....snip...../libsamplerate/src/common.h:226:9: implicit conversion loses integer precision: 'long' to 'int' [-Wshorten-64-to-32]
return lrint (x) ;
Compiling samplerate.c
/Users/.....snip...../libsamplerate/src/common.h:221:9: implicit conversion loses integer precision: 'long' to 'int' [-Wshorten-64-to-32]
return lrintf (x) ;
/Users/.....snip...../libsamplerate/src/common.h:226:9: implicit conversion loses integer precision: 'long' to 'int' [-Wshorten-64-to-32]
return lrint (x) ;
Compiling src_linear.c
/Users/.....snip...../libsamplerate/src/common.h:221:9: implicit conversion loses integer precision: 'long' to 'int' [-Wshorten-64-to-32]
return lrintf (x) ;
/Users/.....snip...../libsamplerate/src/common.h:226:9: implicit conversion loses integer precision: 'long' to 'int' [-Wshorten-64-to-32]
return lrint (x) ;
I'm building after generating Xcode build files (including the config.h file) using cmake like this:
cmake .. -GXcode -DCMAKE_SYSTEM_NAME=iOS
I'm attaching the config.h file here for completeness sake. Since I couldn't attach a .h file, I had to rename it to config.h.txt. config.h.txt
I think the warnings can probably be safely ignored in this case, but it's a bit annoying to see them each time for an otherwise flawless build. So, if there is an easy fix, that might clean it up.
Hi @KoenT-SS
I had a look at the involved code in common.h, and simply adding an (int) cast at the lines of the non-optimized functions here eliminates the warnings:
static inline int psf_lrintf (float x)
{
return lrintf (x) ; // <--- we could add an (int) cast here?
} /* psf_lrintf */
static inline int psf_lrint (double x)
{
return lrint (x) ; // <--- we could add an (int) cast here?
} /* psf_lrint */
but it feels a bit strange to do that, because from their names, both psf_lrintf and psf_lrint seem to have the intent to return a long type, although their call signature is actually defined with an int type...
The SSE2 implementation versions actually use _mm_cv...... calls that effectively return an int type. But the non-optimized versions just return the result of lrintf resp. lrint directly, which is a long type (but since the defined return type is int, it's being converted to int anyway, hence the warnings...)
If it is safe to just add the (int) casts, it might also be better to call the functions psf_irintf and psf_irint or something like that instead, which makes it clear you're not geting a long type but an int type?
Yes it would make sense to add the (int) casts as you suggest.
According to the ISO C standards, lrint and lirtf both return long int and not int.
OK, thanks for confirming. I've edited the code to include the casts in my local copy and it still works just fine (as expected). Would be good if someone with commit permissions adds the casts in the repository. @evpobr ?