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

Gerard Roudier (groudier@club-internet.fr)
Sat, 27 Sep 1997 19:52:14 +0200 (MET DST)


On Sat, 27 Sep 1997, Tom Dailey wrote:

> Gerard Roudier wrote:
> >
> > On Fri, 26 Sep 1997, Tom Dailey wrote:
> >
> > > 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;
> >
> > Your cast is just stupid in my opinion.
> > Your are just assuming that the called function only returns > 0 when it
> > does not return -1.
> > You probably deduce that from 'man read' and I am not sure it is
> > reasonnable to expect from a compiler to do the same. ;-)
> >
> > Imagine the function that is called returns -2. Then your 'cast'
> > has no sense at all.
>
> 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...".

Spreading one's knowledge this way makes one's postings look like jam.
You are off-topic here. The discussion was about the C compiler
warning on signed/unsigned mismatches and as far as I can tell the read()
function is not defined in any C dialect specification.

I am not sure people are still interested by this thread.
Better not to flood the list in my opinion.

Bye,
Gerard.