delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/07/16/09:15:31

From: heretic AT polbox DOT com
Message-Id: <199707161302.PAA20053@free.polbox.pl>
Comments: Authenticated sender is <heretic AT polbox DOT com>
To: djgpp AT delorie DOT com
Date: Wed, 16 Jul 1997 15:05:33 +0000
MIME-Version: 1.0
Subject: fread/fwite return value

hi there

I've noticed a kind of anomaly while writing a program using 
fwrite/fread functions. First take a look at library reference:

size_t  fread(void *_ptr, size_t _size, size_t _nelem, FILE *_stream);

(...)

Return value
============
The number of items of size SIZE read, or -1 on error.

So, I wanted to have error checking and I wrote something like

 if ( fread(blah,blah,blah) == -1 )
 {
    oh_no_error ();
 }

But compiler warned that I am comparing unsigned and signed. And it 
was right: size_t is unsigned long! Anyone knows how fread or fwrite 
can return -1 on error while its return value is unsigned?


---------------------------------------
 With heretic's greeting
       http://www.polbox.com/h/heretic
---------------------------------------

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019