[nanomsg] Re: Fixing compiler warnings regarding type conversions

  • From: Martin Sustrik <sustrik@xxxxxxxxxx>
  • To: nanomsg@xxxxxxxxxxxxx
  • Date: Tue, 01 Oct 2013 12:06:15 +0200

Hi Immanuel,

I started to fix some compiler warnings regarding type conversions.
At some points I'm a bit confused, like the following:
"nanomsg\src\protocols\utils\dist.c(86): warning C4267: 'Funktion':
Konvertierung von 'size_t' nach 'uint32_t', Datenverlust möglich"
The call stack (with the typ of the number of copies) is like this:
nn_msg_bulkcopy: uint32_t
nn_chunkref_bulkcopy: uint32_t
nn_chunkref_addref: int
nn_atomic_inc: uint32_t

Which leads to these conversions (including changes in signedness):
size_t -> uint32_t -> uint32_t -> int -> uint32_t.
And size_t is 8 bytes on x64 instead of 4 bytes on x86 machines. There
are a few situations like that.
Martin, I know that you pointed out the way with nn_assertions, to check
wether values are within limits, but I think a more plattform adapting
solution would be better. One, where only in situations where different
type sizes would prevent communication between x86 applications and x64
applications, a least common type would be used. If that can happen at all.
I know that this claim maybe a little bit bold, as I'm no expert and far
away from understanding nanomsg, but I think consistent typing helps a
lot. In the mentioned situation above, I would use size_t all the way down.
Any thoughts on that?

I would say the 'int' in nn_chunk is some kind of leftover. I believe replacin it by uint32_t would work OK. Would you like to patch it?

Martin


Other related posts: