On Tuesday, March 8, 2016 at 1:23:34 AM UTC+1, Feng Xiao wrote:
>
> In proto2, when a message is serialized, the serialization routine will 
> check the has-bits to determine whether a field is set and only serialize 
> set fields. However, in proto3, we removed has-bits, so the serialization 
> routine can't check the has-bits. As a workaround, we instead check whether 
> the field is set to a non-zero value. That's why proto3 has these "field == 
> 0" comparisons but proto2 doesn't. They are there intentionally, but we may 
> be able to write it in a way that can avoid the float-equal warnings.
>

Hi,

I am sorry to revive this old topic; however, I have the described problem 
(i.e., proto generated files giving a warning when compiled with 
-Wfloat-equal).

I managed to have the same check using std::fpclassify(field) == FP_ZERO 
(instead of field == 0) which avoids float-equal warning. However, it 
includes <cmath> if that is undesirable, equality for floats fields can be 
checked with two inequalities "field <= 0 && field >= 0" which again avoids 
float-equal warning.

I would be happy to send a PR if you think it is appropriate.

Best,
Halil

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.

Reply via email to