6 ms·
(c - 'a') + 'A' contains both
by tlb 7y ago
(c - 'a') + 'A'
contains both
- XMPPwocky 7y agoI thought about saying (c + 'A') - 'a' to make this more clear, but I think that's actually UB with signed chars- e.g. for c='a', 'a'+'A' exceeds the range of a signed 8-bit value! Promotion should save us here, but that's a bit too yikes-y for my comfort.
- kccqzy 7y agoIt does not. Subtracting a char from a char involves usual arithmetic conversions as well and the result is typically an int. Next, you have addition between an int and a char.