Would you like signs with those chars?
Would you like signs with those chars?
Posted Oct 24, 2022 21:14 UTC (Mon) by NYKevin (subscriber, #129325)In reply to: Would you like signs with those chars? by cesarb
Parent article: Would you like signs with those chars?
Posted Oct 24, 2022 22:13 UTC (Mon)
by Sesse (subscriber, #53779)
[Link] (4 responses)
I do wish C had made a separate “byte” type, though, for aliasing reasons. char has too many tasks.
Posted Oct 24, 2022 23:26 UTC (Mon)
by NYKevin (subscriber, #129325)
[Link]
Posted Oct 25, 2022 7:30 UTC (Tue)
by gspr (guest, #91542)
[Link] (2 responses)
Posted Oct 25, 2022 7:34 UTC (Tue)
by Sesse (subscriber, #53779)
[Link] (1 responses)
Posted Oct 25, 2022 19:18 UTC (Tue)
by wahern (subscriber, #37304)
[Link]
Posted Oct 25, 2022 5:09 UTC (Tue)
by SLi (subscriber, #53131)
[Link] (4 responses)
Posted Oct 25, 2022 16:15 UTC (Tue)
by khim (subscriber, #9252)
[Link]
I suspect it was just added when the C Standard committee realized that on some platforms simple
Posted Oct 27, 2022 2:09 UTC (Thu)
by gdt (subscriber, #6284)
[Link] (2 responses)
If the language insists on "char" being "unsigned char" then some processors will need to follow the register load with an AND instruction to clear the sign extension. If loading that register also sets register flags (eg, Negative) then you'll need to clear those register flags too. You could, of course, perhaps avoid this with careful compiler optimisations, but that's asking too much of the compilers of the era.
Well before the ANSI standards committee started work, the convention in C was to let these differences in processor implementations shine through, with an obligation on people writing code intended to be 'portable' between differing processors to deal with the results. Considering that C was a systems programming language, this wasn't an unreasonable choice.
Posted Oct 27, 2022 6:01 UTC (Thu)
by SLi (subscriber, #53131)
[Link]
Posted Oct 27, 2022 7:18 UTC (Thu)
by joib (subscriber, #8541)
[Link]
(That blog post is a few years old and doesn't include results for RISC-V, but I understand that RISC-V is like ARM, in that it provides both zero extending and sign extending byte loads but the ABI has chosen char's to be unsigned)
Would you like signs with those chars?
Would you like signs with those chars?
2. If you must use char, unsigned will work perfectly well (does your Bloom Filter have a negative count?!), so this isn't actually a use case for signed char.
3. If you need a sentinel value, you can use 255; there is no magical rule that says sentinel values have to be negative.
Would you like signs with those chars?
Would you like signs with those chars?
Would you like signs with those chars?
Would you like signs with those chars?
Would you like signs with those chars?
char
is unsigned. They needed single-byte signed type thus signed char
was born.Would you like signs with those chars?
Would you like signs with those chars?
Would you like signs with those chars?