[go-nuts] Carting int to bool and the reverse for bit hacking ?

2020-11-20 Thread christoph...@gmail.com
Go has a strict type separation between int and bool. For a normal usage this is OK. I guess it also ease assembly portability because there is not always a machine instruction to do so. For bit hacking, this is an unfortunate limitation. A handy feature of bool <-> int conversion is that true

Re: [go-nuts] Carting int to bool and the reverse for bit hacking ?

2020-11-21 Thread Aleksey Tulinov
To me your example appears somewhat confusing, int(bool(int())) is the fishiest part IMO. I assume bool(int()) is just (v^v1 != 0) in disguise and this is essentially (v^v1 != 0) & (v^v2 != 0) & (v^v3 != 0) Am i right? Go can't & bools, so func bool2int(b bool) int { // This is what Go compiler