|
|
Subscribe / Log in / New account

Would you like signs with those chars?

Would you like signs with those chars?

Posted Oct 25, 2022 6:35 UTC (Tue) by eru (subscriber, #2753)
In reply to: Would you like signs with those chars? by mb
Parent article: Would you like signs with those chars?

The difference with char and short is that people primarily expect char to contain a character (it's even in its name, and string literals are arrays of char), but shorts are used for numbers. This is why having char as a signed type is insane. Whoever has heard of a negative letter 'A'? Back in eighties when first learning C, and porting C programs from the usenet to my crummy PC/XT clone, I often tripped up because of this, as my language requires more than A-Z to write. It was a real pain.


to post comments

Would you like signs with those chars?

Posted Oct 25, 2022 10:36 UTC (Tue) by geert (subscriber, #98403) [Link] (3 responses)

Don't forget all of this was introduced in the days of 7-bit ASCII[*], so a signed char was fine. In fact it also allows you to store a negative error code, without wasting precious memory on expanding beyond a single byte.
8-bit ASCII (e.g. ISO-8859-*) was only standardized in the eighties, which is about the same time as PowerPC and ARM saw the day of light, so making char default to unsigned may made sense for them (modulo the compatibility issues).

[*] EBCDIC is 8-bit, and seems to have an intentional division in characters with and without bit 7 (the "sign" bit) set.
https://en.wikipedia.org/wiki/EBCDIC#Code_page_layout

Would you like signs with those chars?

Posted Oct 25, 2022 13:15 UTC (Tue) by eru (subscriber, #2753) [Link] (1 responses)

8-bit character sets were not that new, although I agree they mostly post-date C. The Commodore micros since the 1970's used "PETSCII" with graphics characters in the upper half, and the IBM PC has since 1981 had its own character set with ASCII in the lower half, and a mixture of graphics and accented letters in upper (selection depending on the region).

Would you like signs with those chars?

Posted Oct 25, 2022 19:58 UTC (Tue) by khim (subscriber, #9252) [Link]

> 8-bit character sets were not that new, although I agree they mostly post-date C.

Note that bunch of these was in wide use way before C was a thing.

Would you like signs with those chars?

Posted Nov 4, 2022 20:07 UTC (Fri) by fest3er (guest, #60379) [Link]

This is why the DEC-10 was nice. Bytes could be defined from 1 to 36 bits in length. Granted, this could result in unused bits in words, but that's the price of flexibility. :)


Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds