I am making no assumptions, other than that this code is executing on
a POSIX-compliant UNIX system. According to ANSI/IEEE Std 1003.1,
section 6.4.1.3, "Upon successful completion, read() shall return an
integer indicating the number of bytes actually read. Otherwise, read()
shall return a value of -1 and set errno to indicate the error...".
>
> In the initial post the construct was:
>
> if (n < 0)
> ....
> else
> ...
>
> At the else statement, it is trivial that 'n' is never negative and
> the compiler warning is quite _useless_. No need for the compiler to
> be as knowledgeable as you are in order to handle this.
>
> > Then, nr_of_bytes_read can be dealt with in whatever way desired. I know
> > this is clumsy, but that is the price one pays for semantic overloading
> > of the return value from read. (By the way, ()s are not required around
> > sizeof's argument if it is a variable name -- only if it is a type
> > name.)
>
> My understanding of your proposal is: to use 2 variables and a signed to
> unsigned cast each time we call a function that returns a signed value
> that could be potentially compared to a sizeof() or some other unsigned
> value. I just hope I just misunderstood your suggestion.
No; you have understood my suggestion correctly. This seems to me to be
the
clearest way to deal with such an unfortunate situation. When comparing
the
return value to -1, it clearly makes the most sense for the return value
to be of a
signed type, as in fact the POSIX standard decrees (in this case,
ssize_t).
On the other hand, if the return value is to be compared to an unsigned
value,
such as a value of type size_t, then it makes the most sense for the
return
value to be of an unsigned type.
>
> Gerard.