Re: Warnings when using % operator
Tim wrote:[color=blue]
> ... The signed/unsigned comparison in the
> 'for' control clause gets flagged with a
> warning. Am I on track?[/color]
Sort of. In fact, Ben explained the problem in his response to me:
"When `a' and `b' are unsigned, `a % b'
is always nonnegative. Thus, ((i) % (j)) < 0
is always false in this case, hence the
first warning. That subexpression is the
first part of a ?: expression, hence the
second warning." -- Ben, 15 Sep 2004
So the problem arises when the IMOD macro is used. Regarding your
suggestion, I note that Plauger says:
"You should make a point of using type
size_t *anywhere* your program
performs array subscripting or address
arithmetic."
-- P.J. Plauger, The Standard C Library
Thanks for your post.
Martin
Tim wrote:[color=blue]
> ... The signed/unsigned comparison in the
> 'for' control clause gets flagged with a
> warning. Am I on track?[/color]
Sort of. In fact, Ben explained the problem in his response to me:
"When `a' and `b' are unsigned, `a % b'
is always nonnegative. Thus, ((i) % (j)) < 0
is always false in this case, hence the
first warning. That subexpression is the
first part of a ?: expression, hence the
second warning." -- Ben, 15 Sep 2004
So the problem arises when the IMOD macro is used. Regarding your
suggestion, I note that Plauger says:
"You should make a point of using type
size_t *anywhere* your program
performs array subscripting or address
arithmetic."
-- P.J. Plauger, The Standard C Library
Thanks for your post.
Martin
Comment