nmh-workers
[Top] [All Lists]

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

2013-02-05 10:51:14
Ken Hornstein <kenh(_at_)pobox(_dot_)com> writes:
So since the prototype for functions like strcpy() and the like are "char",
in theory this would suppress the warnings.  But still ... I understand
David's reasons for wanting to use unsigned char (it feels more correct
to me as well), but I hate the idea of relying on specific C compiler
options.  For better or worse the POSIX API has pretty much mandated
that C character strings are "char", and casting the arguments to the
ctype macros seems to be the way the world deals with that.

FWIW, strings as "char *" and then explicitly casting all ctype.h macro
arguments to "unsigned char" is the solution the postgresql project has
been using for quite some time, so I'm familiar with it.  It works; the
main downside is that if you forget the "(unsigned char)" someplace,
you won't get any warning that the usage is unportable, and most likely
you won't notice the mistake in testing either.

I have one machine on which I've hacked things up so that I do get a
warning from such constructs --- what you need is for the ctype macros
to expand to array references, and then make sure gcc's warn-for-char-
used-as-subscript option is on.

                        regards, tom lane

_______________________________________________
Nmh-workers mailing list
Nmh-workers(_at_)nongnu(_dot_)org
https://lists.nongnu.org/mailman/listinfo/nmh-workers

<Prev in Thread] Current Thread [Next in Thread>