Skip to content

Instantly share code, notes, and snippets.

@stevegt
Created July 10, 2020 00:25
Show Gist options
  • Save stevegt/abc6b627b0a57b78f9f83f2c9e2d1692 to your computer and use it in GitHub Desktop.
Save stevegt/abc6b627b0a57b78f9f83f2c9e2d1692 to your computer and use it in GitHub Desktop.
playing with Go "cannot take the address of" temporary variable
// b := []byte("lksajflkd sajfsasdjkf lkfjsalkjf salkfjsa lkfj lalkjasfd lkj")
// this works, but we should be able to not have to do this in so many steps
// bBlob := Blob(b)
// pBlob := &bBlob
// this doesn't work
// cannot take the address of Blob(b)
// pBlob := &Blob(b)
// we're asking Go to do something like this, getting the address of a temporary variable
// pBlob := (x := string(b); return &x)
// this works, but prevents us from using the custom Blob type
// pBlob := &b
// this doesn't work either, so the problem has nothing to do with custom types
// pBlob := &(string(b))
//
// pBlob := assignBlobPointer(b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment