www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1995/10/17/04:15:10

Date: Tue, 17 Oct 1995 09:32:38 +0200 (IST)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
To: Erik Max Francis <max AT alcyone DOT darkside DOT com>
Cc: djgpp AT sun DOT soe DOT clarkson DOT edu
Subject: Re: CTYPE Functions

On Fri, 13 Oct 1995, Erik Max Francis wrote:

> mictali AT netcom DOT com (Jere McDevitt) writes:
> 
> > My question is "Is this the proper behavior for isprint? Afterall, 0x121
> > isn't >= 0x20 && <= 0x7e, so why does it return true?"
> 
> Since 0x121 is not representable by an unsigned char under DJGPP, 
> you're completely at the mercy of the compiler.  In this particular 
> case, it appears that DJGPP chooses the more efficient operation (not 
> bothering to bound the check above by 0x100).

DJGPP v1.x library has a bug in its ctype functions: they all use their 
arguments as an int index into an array of flags which tell what 
properties that character has.  When you pass a value which is more than 
127 decimal, this makes a negative index, which means you are outside of 
the table limits, and can get ANY value as the result.  You should cast 
the argument to unsigned char to make these functions work.  Of course, 
passing a value which is greater than 255 decimal is also a programmer's 
bug.

- Raw text -


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