Thomas David Rivers wrote:
> > > So why is using a "char" as an array subscript wrong? I had always
> > > avoided it because the compiler complained and that was good enough
> > > for me.
> >
> > Because your char value could be negative and end up referencing memory
> > before your array start. Mainly a problem with the ctype macros and
> > high-ascii characters.
> >
>
> That's an interesting reason... any variable can be negative (well,
> except for the unsigned types...) - what's so interesting about
> `char'? Is it simply ctype macros that are the concern, or something
> "bigger"?
What's interesting about char is that it's implementation defined
whether "plain" char is the equivalent of "signed char" or "unsigned
char" (or even something else).
So, given an 8-bit, two's complement implementation of char, the
statement
char i = 128;
may cause 'i' to end up as -128 or 128, for example.
An implementation-defined value to your subscript is almost never
useful, so this kind of behavior does warrant a warning. You'll
notice gcc doesn't warn if explicitly signed or unsigned chars are
used as subscripts, as then there is no uncertainty.
--
Robert Nordier
[EMAIL PROTECTED]
[EMAIL PROTECTED]
To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message