[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Nmh-workers] Compiler warnings and signed vs. unsigned char, again

From: David Levine
Subject: Re: [Nmh-workers] Compiler warnings and signed vs. unsigned char, again
Date: Tue, 05 Feb 2013 14:05:55 -0500

Lyndon wrote:

> But to what benefit?  I.e. where is the gain in using
> "unsigned char" rather than just reverting to "char"
> everywhere.  This is what the C library uses for for its
> string and stdio functions.

I see two broad approaches to dealing with the issue:

1) use unsigned char everywhere internally, and cast (to
   char *) arguments to string functions to prevent compiler
   warnings about unsigned char/char * mismatch, or

2) use char everywhere internally, and cast (to unsigned
   char) arguments to ctype macros to prevent incorrect sign

"everywhere" means where we store message contents.  printf
format strings, user responses, and other really internal
uses can remain char *.

I prefer the first because 1) we deal with chars that we,
within nmh, always interpret as unsigned, and 2) if we
forget a cast of unsigned char * to char * in a call to
strcmp(), etc., there's no harm.

Though seeing the arguments, I'm OK with the second
approach.  Especially if we get the compilers to flag
missing casts.

> The only time signed vs. unsigned makes a difference is if
> you are using chars as itty bitty ints.  Are we doing
> that?

Not that I recall but I wouldn't be surprised if some are
lurking, though I would be surprised if any of those could
contain a value >0x7f.  In any case, I agree that we should
exterminate any chars used as ints if we find them.

> Switching to unsigned char means casting every parameter
> to almost every str* and stdio function call.  Besides
> being tedious, these casts will mask the cases where
> signed vs. unsigned actually matters.  This is just bad
> programming.

I don't think we have many stdio function calls that would
be affected.  And for both those and str* calls, when would
it matter they were passed an unsigned char * instead of a
char *?

And I think it's worse programming to risk incorrect
behavior if someone forgets an unsigned char cast and the
compiler doesn't warn about it.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]