Channel pointer passing

1,070 views
Skip to first unread message

si guy

unread,
Jul 24, 2011, 6:13:34 PM7/24/11
to golan...@googlegroups.com
In the various Go documents it is stated that channel values are *always* pointers (effectively).
Simple question, does this include channels that are embedded in nested structs.
eg:
type A struct {
B
}

type B struct {
myCh chan interface{}
}

Can I pass an instance of A as a value, and still retain the myCh pointer? or will it make a new zero-value channel if I do that?

si guy

unread,
Jul 24, 2011, 6:18:17 PM7/24/11
to golan...@googlegroups.com
Whoops! I totally forgot to include my original question:
Will said pointer behaviour be true in _all_ cases.

Russ Cox

unread,
Jul 24, 2011, 6:57:08 PM7/24/11
to golan...@googlegroups.com
On Sun, Jul 24, 2011 at 18:13, si guy <sjw...@gmail.com> wrote:
> In the various Go documents it is stated that channel values are *always*
> pointers (effectively).
> Simple question, does this include channels that are embedded in nested
> structs.
> eg:
> type A struct {
>
> B
>
> }
> type B struct {
>
> myCh chan interface{}
>
> }
> Can I pass an instance of A as a value, and still retain the myCh pointer?

Yes. Copying just copies all the field values,
as if by repeated assignment statements.
It doesn't do anything special.

Russ

si guy

unread,
Jul 25, 2011, 7:15:30 AM7/25/11
to golan...@googlegroups.com
Thanks!
Reply all
Reply to author
Forward
0 new messages