[ofa-general] RE: [PATCH] rdma_cm: fix port type (fix bug 557)

Jason Gunthorpe jgunthorpe at obsidianresearch.com
Mon Jun 4 13:24:12 PDT 2007


On Mon, Jun 04, 2007 at 12:37:39PM -0700, Sean Hefty wrote:
> >Even if next_port is initialized to a negative value by get_random_bytes, I
> >would expect next_port to be set to a positive value between 
> >local_port_range[0]
> >and local_port_range[1] by the next statement.  I'm not seeing the error 
> >my my
> >math/logic here.
> 
> My my English needs help, but here's the definitions for '%' in C89 and 
> C99 according to Wikipedia:

The C99 '%' operator is actually a remainder operator, not a modulo
operator.. These two things are identical until you consider the
effect of negative numbers:

-1 modulo 4 = 3
-1 modulo -4 = -1
-1 remainder 4 = -1    # C99 defintion of %
-1 remainder -4 = -1

Lagunages that have both a remainder and a modulo operator operate as
above. Other languages often like to call remainder modulo, so it is
all very confusing.

For C, it is best if you never use signed numbers with % since prior
to C99 it was undefined if it is remainder or modulo. Also, in
general, most people don't want remainder when they think of % in C.

Jason



More information about the general mailing list