3 ms·
If we're using our time machines to fix C, can we make a special type that's identical to unsigned int but can use all the bit-wise operators, requiring an expl
by billpg 7y ago
If we're using our time machines to fix C, can we make a special type that's identical to unsigned int but can use all the bit-wise operators, requiring an explicit conversion operators between regular int and bitwise int.
bitwise x = 0x1234;
x |= 0x1000;
(0x indicates a bitwise value.)
- colejohnson66 7y agoI wouldn’t use 0x as that is used commonly to refer to hexadecimal values. Unless that was your intent and those are hexadecimal
- billpg 7y agoThat was indeed my intention. Remember we're hypothetically reinventing C from scratch so there's no legacy code to worry about. By making 0x literals of bitwise type, they can only be used with bitwise operators. Decimal literals are regular integers so can only use arithmetic operators. If you want to use a hexadecimal value with arithmetic operators or decimal values with bitwise operators, use the operator that converts one type to another.