Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

They discuss that in the thread. Consensus seems to be to warn when seeing “2 ^ (certain base-10 literals)”.

It’s uncommon to use base 10 when bit-twiddling with the XOR operator - so this makes sense.

Of course, it would be better if C-family languages didn’t use ^ for XOR in the first place.



>Of course, it would be better if C-family languages didn’t use ^ for XOR in the first place.

I think at the time they were created there simply wasn't an ambiguity in anybody's mind. POW is a relatively complex operation, I don't think anybody expected it as a builtin operator (much like SQRT and friends). Arguably so is DIV but I suppose that's too convenient not to have.

XOR on the other hand is something you really want to be a builtin operator in a low level, bit-twiddling language like C, so getting a dedicated operator makes sense. I'm not sure if an other sigil would've made more sense, after all ASCII lacks ⊕.


Algol 68 and Fortran both had . In fact, COBOL 60 even supported so not sure why anyone would not expect it as builtin for C.


> I think at the time they were created there simply wasn't an ambiguity in anybody's mind.

And why would anyone in their right mind do 23 and not 1<<3? At least among the crowd who knows pow is expensive and what xor is.


Do they not currently/do they plan to track macro expansion well enough to distinguish between macros and literals? I feel like they should be able to get the best of both worlds here.


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.)


I wouldn’t use 0x as that is used commonly to refer to hexadecimal values. Unless that was your intent and those are hexadecimal


That 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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: