Topic: Bug Report for ANSI C - char signedness
Author: James Kanze <james-albert.kanze@vx.cit.alcatel.fr>
Date: 1997/01/27 Raw View
David R Tribble <david.tribble@central.beasys.com> writes:
|> Randy Meyers <rmeyers@decc.ENET.dec.com> wrote:
|> > Various people agreed with the following statement:
|> >
|> >> It seems to me that what you have found is a requirement that locale
|> >> support for ISO-8859-1 [Latin-1] requires that char be unsigned.
|>
|> > If you are using the is* functions on the result of getchar() and
|> > friends, there's no problem since you are dealing with an int in the
|> > proper canonical form. If you are dealing with pure strings, it would
|> > be wise to declare them as unsigned char.
|>
|> But that's precisely my point: Standard C *requires* you to do this (for
|> maximally correct behavior and portability), and yet none of the standard
|> library functions (e.g., strcmp()) accept 'unsigned char *' arguments.
|> Wouldn't C (and C++) be more consistent (between the language and its
|> library) if you could declare pure strings as simply 'char'?
The problem is not only with the standard library functions (although
you cannot even read an unsigned char with fgets): you cannot even
assign a string literal to an unsigned char*.
For better or worse, the only solution is to declare all of the
strings/arrays as char, and cast to unsigned char whenever reading from
them.
--
James Kanze home: kanze@gabi-soft.fr +33 (0)1 39 55 85 62
office: kanze@vx.cit.alcatel.fr +33 (0)1 69 63 14 54
GABI Software, Sarl., 22 rue Jacques-Lemercier, F-78000 Versailles France
-- Conseils en informatique industrielle --
---
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: David R Tribble <david.tribble@central.beasys.com>
Date: 1997/01/24 Raw View
Randy Meyers <rmeyers@decc.ENET.dec.com> wrote:
> Various people agreed with the following statement:
>
>> It seems to me that what you have found is a requirement that locale
>> support for ISO-8859-1 [Latin-1] requires that char be unsigned.
> If you are using the is* functions on the result of getchar() and friends,
> there's no problem since you are dealing with an int in the proper canonical
> form. If you are dealing with pure strings, it would be wise to declare
> them as unsigned char.
But that's precisely my point: Standard C *requires* you to do this (for
maximally correct behavior and portability), and yet none of the standard
library functions (e.g., strcmp()) accept 'unsigned char *' arguments.
Wouldn't C (and C++) be more consistent (between the language and its
library) if you could declare pure strings as simply 'char'?
-- David R. Tribble, david.tribble@central.beasys.com --
---
[ comp.std.c++ is moderated. To submit articles: Try just posting with your
newsreader. If that fails, use mailto:std-c++@ncar.ucar.edu
comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
Comments? mailto:std-c++-request@ncar.ucar.edu
]
Author: brad@cfar.umd.edu (Brad Stuart)
Date: 1997/01/25 Raw View
David R Tribble (david.tribble@central.beasys.com) wrote:
: But that's precisely my point: Standard C *requires* you to do this (for
: maximally correct behavior and portability), and yet none of the standard
: library functions (e.g., strcmp()) accept 'unsigned char *' arguments.
: Wouldn't C (and C++) be more consistent (between the language and its
: library) if you could declare pure strings as simply 'char'?
IMO, it would be more consistent if you could declare pure strings as
simply 'string' and not worry about char, char*, unsigned char,
c_str(), safe conversions, and the like. But, as you say, the
standard library still requires char *, even though we have perfectly
good strings.
Brad
--
| Brad Stuart brad@cfar.umd.edu
| Center for Automation Research
| University of Maryland, College Park
---
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: Darron.Shaffer@beasys.com (Darron Shaffer)
Date: 1997/01/25 Raw View
In article <2.2.32.19970124024102.002fc524@central.beasys.com>, David R
Tribble <david.tribble@central.beasys.com> wrote:
>Randy Meyers <rmeyers@decc.ENET.dec.com> wrote:
>> Various people agreed with the following statement:
>>
>>> It seems to me that what you have found is a requirement that locale
>>> support for ISO-8859-1 [Latin-1] requires that char be unsigned.
>
>> If you are using the is* functions on the result of getchar() and friends,
>> there's no problem since you are dealing with an int in the proper
>> canonical form. If you are dealing with pure strings, it would be wise
>> to declare them as unsigned char.
>
>But that's precisely my point: Standard C *requires* you to do this (for
>maximally correct behavior and portability), and yet none of the standard
>library functions (e.g., strcmp()) accept 'unsigned char *' arguments.
>Wouldn't C (and C++) be more consistent (between the language and its
>library) if you could declare pure strings as simply 'char'?
The key issue here, in my opinion, is that all of the standard C library
routines I have checked state that they treat characters as unsigned. So the
library assumes characters are unsigned but the language is unspecified!
Why this inconsistency?
This means that when you want to write portable code you must do something
like:
1) Declare most/all char variables as unsigned.
2) Cast every time you call a standard library routine.
I for one don't like to have casts all through my code.
--
Darron Shaffer
Darron.Shaffer@beasys.com
---
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]