Hello..
First, thank you for the effort to provide LMDB to the community. I'm compiling LMDB 0.9.17 using msvc2013 x64 and it compiled successfully with
only one warning: mdb.c(7224): warning C4333: '>>' : right shift by too large amount, data loss.
Is this something I need to correct and if so, how would I go about it please?
Thank you,
John
John GM44 wrote:
Hello..
First, thank you for the effort to provide LMDB to the community.
You're welcome.
I’m compiling LMDB 0.9.17 using msvc2013 x64 and it compiled successfully with
only one warning: mdb.c(7224): warning C4333: '>>' : right shift by too large amount, data loss.
Is this something I need to correct
No, it's harmless.
and if so, how would I go about it please?
Since you are working with an open source C library, you really ought to learn how to read C - at least enough to be able to understand why this is harmless.
John wrote:
only one warning: mdb.c(7224): warning C4333: '>>' : right shift by too large amount, data loss.
It looks to me that the SETDSZ(node,size) macro that is generating that warning on that line is called three times in mdb.c, twice with a size_t (unsigned int) size, and once, on line 7224 (line varies by version of mdb.c) with an indx_t (unsigned short) size.
The SETDSZ() macro does a right shift by 16 bits to get the higher two bytes of the size, which is necessary when the size is a size_t (the other two calls), but always produces zero when the size is an unsigned short (this call giving the warning.)
The poorly worded compiler warning is telling us that it's silly (from the perspective of the compiler) to be right shifting a 16 bit unsigned short by 16 or more bits to the right. The result will -always- be zero, suggesting to the compiler that the shift might not be what the programmer intended.
If this were my software, I would consider changing that invocation of the SETDSZ() macro
from: SETDSZ(node, nsize);
to: SETDSZ(node, (size_t)nsize);
to avoid the warning, with no impact on the resulting machine code, but with the benefit of (minimally) documenting, right in the source code, awareness that this invocation of the SETDSZ is working with a size that is not of the size_t type expected by the SETDSZ macro.
I have -not- tested the above claims in a Microsoft development environment ... the possibility for error is non-trivial.
It's better in my view to have no warnings, if that can be done without compromising the generated code, and only a minor inconvenience to the source code.
Even for experienced C coders (such as myself, who has written many hundreds of thousands of lines of C code in the last 40 years), the difference in time spent to ensure that all is well, so far as compiler warnings can detect, is substantially less ... 0 minutes versus N minutes, when there are zero warnings, rather than one or more warnings.
In my experience, allowing -any- warnings increases the risk that another future warning that was important will be ignored (probably not by Howard, who knows exactly what is going on, but perhaps by someone else working with the code.)
openldap-technical@openldap.org