Re: Question about -Wchar-subscripts

2000-10-03 Thread Dan Nelson

In the last episode (Oct 03), Larry Lile said:
 
 ...we get scores of warnings about using characters as subscripts
 to an array (-Wchar-subscripts), which generates so much noise as
 to mask real warnings burried within. Therefore, I would like to
 suppress this warning unless someone can explain why using a char
 as an array subscript is in any way an illegitimate thing to do.
 As far as I can tell, getting rid of the warning by changing the
 code would require adding a large number of frivolous casts to
 scores of source files...
 
 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.

-- 
Dan Nelson
[EMAIL PROTECTED]


To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message



Re: Question about -Wchar-subscripts

2000-10-03 Thread Thomas David Rivers

 
 In the last episode (Oct 03), Larry Lile said:
  
  ...we get scores of warnings about using characters as subscripts
  to an array (-Wchar-subscripts), which generates so much noise as
  to mask real warnings burried within. Therefore, I would like to
  suppress this warning unless someone can explain why using a char
  as an array subscript is in any way an illegitimate thing to do.
  As far as I can tell, getting rid of the warning by changing the
  code would require adding a large number of frivolous casts to
  scores of source files...
  
  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"?

- Dave R. -
 


To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message



Re: Question about -Wchar-subscripts

2000-10-03 Thread Leif Neland


- Original Message -
From: "Dan Nelson" [EMAIL PROTECTED]
To: "Larry Lile" [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Sent: Tuesday, October 03, 2000 9:49 PM
Subject: Re: Question about -Wchar-subscripts


 In the last episode (Oct 03), Larry Lile said:
 
  ...we get scores of warnings about using characters as subscripts
  to an array (-Wchar-subscripts), which generates so much noise as
  to mask real warnings burried within. Therefore, I would like to
  suppress this warning unless someone can explain why using a char
  as an array subscript is in any way an illegitimate thing to do.
  As far as I can tell, getting rid of the warning by changing the
  code would require adding a large number of frivolous casts to
  scores of source files...
 
  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.

How about unsigned char? Could that be used for index?

Leif




To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message



Re: Question about -Wchar-subscripts

2000-10-03 Thread Thomas David Rivers

Robert Nordier [EMAIL PROTECTED] wrote:
 
 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

 Ah - yes!  That makes perfect sense... when you consider
 that `char' all alone can be signed or unsigned...

 Thanks for the explanation!

- Dave Rivers -




To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message