Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

encoding/gob: turns pointers-to-zero into nil pointers #4609

reinerp opened this issue Jan 4, 2013 · 3 comments

encoding/gob: turns pointers-to-zero into nil pointers #4609

reinerp opened this issue Jan 4, 2013 · 3 comments


Copy link

@reinerp reinerp commented Jan 4, 2013

See The pointer-to-one gets turned into a
pointer-to-one, but the the pointer-to-zero gets turned into a nil pointer.
Copy link

@dsymonds dsymonds commented Jan 7, 2013

Comment 2:

I'm not sure this is even considered a bug; I think this is how gobs are supposed to
work. Per, pointers are flattened, so encoding
struct{x *int}{&0} (using "&0" as a notation for pointer to an int with value zero) is
intended to be equivalent to encoding struct{x int}{0}, which is specified to not be
explicitly encoded.
It's a shame that this means that encoding/gob can't preserve things like protocol
buffers, but that's just the way it is. The workaround there is to encode the proto
yourself, and encode []byte via gobs instead.

Labels changed: added priority-later, packagechange, removed priority-triage, go1.1.

Owner changed to @robpike.

Status changed to Thinking.

Copy link

@robpike robpike commented Feb 13, 2013

Comment 3:

A consequence of the design. Perhaps unfortunate, but not going to change.

Status changed to WorkingAsIntended.

Copy link

@minux minux commented Apr 12, 2013

Comment 4:

Issue #5275 has been merged into this issue.

@golang golang locked and limited conversation to collaborators Jun 24, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants
You can’t perform that action at this time.