Re: SOLUTION (Re: Style question: comparison between signed and unsigned?)

Tom Dailey (dailey@deltanet.com)
Fri, 26 Sep 1997 12:21:00 -0700


Morten Welinder wrote:
>
> Oops, I didn't look to see what was inside that sizeof()! Anyway,
> the idea is still sound as long as the two sizeof()s agree which,
> I claim, is common.
>
> Morten
> ("simplify the problem as much as possible, but no more than that"
> -- freely after Einstein.)

Your solution is close to being correct, POSIXwise. The completely
"compliant" way of doing this is

ssize_t read_return_value;
size_t nr_of_bytes_read;
...
read_return_value = read ( socket, buffer, sizeof buffer );
if ( read_return_value == -1 ) {
... /* Handle the error. */
}
nr_of_bytes_read = (size_t) read_return_value;
...

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.)

Tom Dailey