Topic: 8-bit characters
Author: mikes@abc.se (Mikael Steldal)
Date: 1995/12/30 Raw View
>Most modern machines will use ISO 8859-1, which doesn't have this problem
>(but has a >number of codes with the 8th bit set, which introduces a set of
>problems of its own).
Yes, that could cause problems if you use a stupid compiler which
defines char as signed by default. It would be good if the standard
mandated char to be unsigned.
---
[ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
Contact address: std-c++-request@ncar.ucar.edu. The moderation policy
is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Author: R.Moeskops@ft.hse.nl (Richard Moeskops)
Date: 1996/01/06 Raw View
>>Most modern machines will use ISO 8859-1, which doesn't have this problem
>>(but has a >number of codes with the 8th bit set, which introduces a set of
>>problems of its own).
>Yes, that could cause problems if you use a stupid compiler which
>defines char as signed by default. It would be good if the standard
>mandated char to be unsigned.
I thought all 'basic' types are and should be signed. Isn't that why the
keyword 'unsigned' exists. Many programmers and many compilers have the type
'uchar' for an unsigned char. If one expects problems with 8-bit characters
use 'typedef unsigned char uchar' or use plain ints to handle the characters.
Nappy Yew Hear
Richard Moeskops
---
[ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
Contact address: std-c++-request@ncar.ucar.edu. The moderation policy
is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Author: fjh@munta.cs.mu.OZ.AU (Fergus Henderson)
Date: 1996/01/06 Raw View
R.Moeskops@ft.hse.nl (Richard Moeskops) writes:
>[someone writes:]
>>Yes, that could cause problems if you use a stupid compiler which
>>defines char as signed by default. It would be good if the standard
>>mandated char to be unsigned.
>
>I thought all 'basic' types are and should be signed.
Nope, it is implementation-defined whether or not `char' is signed.
>Isn't that why the keyword 'unsigned' exists.
If that were really the reason, how would you explain the
existence of the `signed' keyword? ;-)
>Many programmers and many compilers have the type
>'uchar' for an unsigned char. If one expects problems with 8-bit characters
>use 'typedef unsigned char uchar' or use plain ints to handle the characters.
Easier said than done. You will have to do a lot of casting.
For example, the following is not legal
uchar *p = "hello world";
You have to write
uchar *p = (uchar *) "hello world";
You will then also have to write
puts((char *)p);
rather than just
puts(p);
--
Fergus Henderson WWW: http://www.cs.mu.oz.au/~fjh
fjh@cs.mu.oz.au PGP: finger fjh@128.250.37.3
---
[ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
Contact address: std-c++-request@ncar.ucar.edu. The moderation policy
is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]