delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/1997/12/17/06:08:58

Sender: vheyndri AT rug DOT ac DOT be
Message-Id: <3497B2AC.5E0A@rug.ac.be>
Date: Wed, 17 Dec 1997 12:08:28 +0100
From: Vik Heyndrickx <Vik DOT Heyndrickx AT rug DOT ac DOT be>
Mime-Version: 1.0
To: djgpp-workers AT delorie DOT com
Subject: char != unsigned char... sometimes, sigh

Hi workers,

Suppose you have a C program section:

int a ='\x84';
int b;

b = getc (f); // f is a text file with the next character to read 0x84

if (a == b)
  return true;

return false;

I suppose, I don't have to mention that false is returned. I now,
assigned a value of '\x84' is not the smartest thing to do, but I think
this should be rather considered a bug than a feature.

The reason is that getc returns a value in the range [0..255] or -1, and
chars are signed on this platform.

Since getc is only supposed to be used for text files, I think we should
change it to return chars in the range [-128..127], so that comparisons
work.

If no objections, I'll make the patches.

BTW there may be other functions with similar problems, I'll change
those too. I'll be careful about those changes.

Regards.

-- 
 \ Vik /-_-_-_-_-_-_/   
  \___/ Heyndrickx /          
   \ /-_-_-_-_-_-_/

- Raw text -


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