When compiling with Xcode 10.2.1, there are a couple of compiler warnings
mobileben opened this issue · 2 comments
pcg_variants.h:158:49: warning: implicit conversion loses integer precision: 'unsigned long long' to 'uint32_t' (aka 'unsigned int') [-Wshorten-64-to-32]
return pcg_rotr_32(((state >> 18u) ^ state) >> 27u, state >> 59u);
pcg-c/extras/entropy.c:76:36: warning: comparison of integers of different signs: 'ssize_t' (aka 'long') and 'size_t' (aka 'unsigned long') [-Wsign-compare]
return (close(fd) == 0) && (sz == size);
The sign-compare one is easy to fix (and I've done so). The implicit conversion one probably ought to be fixed by making all implicit conversions explicit. That's a bigger patch than one line, and I'm also not sure that's a good idea overall.
I do also build this using GCC on Ubuntu and took at the compile logs (I mainly build to run and test on the Mac so I tend to not examine the build results as much).
The entropy.c signed warning which you fixed does show up in older build logs. But at least with my build config with GCC, there are no precision loss warnings. Those only show up with clang.
I do see what you mean about this being more than a one line fix. An alternative would be to use a #pragma
This for example
#if __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wconversion"
#endif /* __clang __ */
This obviously needs a pop later on. And this also may be deemed a bit heavy handed.
The other way would be to add casts where necessary. Based on taking a look at the code, the places where I see they need it do look like true downcasts of integers.
In general my code is clean of warnings. So this one unfortunately pops up in several places.