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

>We can’t use unsafe.SizeOf as it is not a constant expression

I'm not sure why Dave claims this, since the docstring of unsafe.Sizeof says, "The return value of Sizeof is a Go constant," and this can be trivially verified: https://play.golang.org/p/OvShLD4KLKY

By the way, it turns out you can exploit Go's map initialization rules to assert arbitrary boolean expressions at compile time: https://twitter.com/lukechampine/status/1026695476811390976

And this turns out to be rather useful in combination with unsafe.Sizeof, since you can use it to write compile-time assertions about the size of your types.



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

Search: