We were unable to load Disqus. If you are a moderator please see our troubleshooting guide.

Jeff R. Allen • 4 years ago

Fun stuff, thanks!

In the interest of protecting junior Go programmers from themselves, could you please put a note on this explaining how bad and horrible this is, and that is almost certainly does not belong in production code?

Perhaps explaining to them that it is not an accident that the unsafe package is named "unsafe". Or demonstrating how to use your new package to make segfaults, and pointing out that the nice thing about Go is that it wouldn't have segfaulted, if you hadn't been trying to make it. :)


PS: A fun thing to do is try to mutate a string by hacking the dataptr of a []byte to point at the same place as the string's dataptr, then modifying it. You get a crash because the strings are put in read-only memory by the linker.

Tiago Katcipis • 4 years ago

Your hack idea seems fun indeed, it got me thinking if it would be always read only, when I do stuff like:

str := string(someDynamicByteArray)

It seems hard to think about as read only, will do some testing soon =). Thanks.

Jon Forrest • 4 years ago

"Compiled it outputing it’s assembly" ->
"Compiled it outputing its assembly"

(There are additional examples of this mistake on the page.)

Tiago Katcipis • 4 years ago

Thanks Jon, fixed it.