delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/07/16/11:18:21

From: Andrew Crabtree <andrewc AT typhoon DOT rose DOT hp DOT com>
Message-Id: <199707161515.AA104406147@typhoon.rose.hp.com>
Subject: Re: fread/fwite return value
To: heretic AT polbox DOT com
Date: Wed, 16 Jul 1997 8:15:47 PDT
Cc: djgpp AT delorie DOT com
In-Reply-To: <199707161302.PAA20053@free.polbox.pl>; from "heretic@polbox.com" at Jul 16, 97 3:05 pm

> But compiler warned that I am comparing unsigned and signed.
So tell the compiler to shut up.  With GCC 2.7.2.2 and earlier, you
must explicitly ask it to report signed/unsigned comparison problems
with -Wsign-compare.  That is -Wall does not include it.
  The latest developers version (last year or 
so) of gcc, along with pgcc as well, include -Wsign-compare along
with -Wall.  So, either remove -Wsign-compare if you are using
it, or add -Wno-sign-compare after -Wall if you have a developers
version.

> 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?
Remember, intel uses 2's complement, which are represented in 
32 bit values just like unsigned are.

Take -1

1) Remove the sign, you get 

0x00000001

2) Complement the number 

0xFFFFFFFE

3) Add one to it

0xFFFFFFFF

Most people think its easier to write negative one, and have it converted
into its unsigned representation, that to write out that huge value.

Andrew





- Raw text -


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