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

I'd been using xor swapping for years as x ^= y ^= x ^= y; until some point it occurred to me that this has undefined behavior in C.


That's one thing missing from BASIC in other programming languages, the SWAP statement: SWAP x y

So few other languages have it, some languages even make it impossible to write a swap function by not supporting pass by reference or pointers. Python has something interesting except it requires typing the name of each variable twice




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

Search: