Re: [go-nuts] Go has confusing pointers

2020-06-19 Thread Tyler Compton
> > c is of type *Count (pointer to Count), surely? > Yes, my mistake! Thank you for the correction. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+

Re: [go-nuts] Go has confusing pointers

2020-06-19 Thread howardcshaw
c is of type *Count (pointer to Count), surely? It is (*c) that is of type Count, which has to be cast to int to be returned as such because Go requires explicit casts. Agree with the rest. On Friday, June 19, 2020 at 12:44:26 PM UTC-5, Tyler Compton wrote: > > In this case, c is of type Count,

Re: [go-nuts] Go has confusing pointers

2020-06-19 Thread Tyler Compton
> > *c = *c + 1 //why use *c and not just c, based on (c *Count) c is already > a pointer? > In Go (as well as other languages like C) '*' plays two roles. When used with a type like in "c *Count", it tells you that c is a pointer to a Count object. When used on a variable, like "*c + 1", it dere

Re: [go-nuts] Go has confusing pointers

2020-06-19 Thread Michael Jones
this says "increment the data c points at" not "increment the pointer" the function is returning an int instead of a Count On Fri, Jun 19, 2020 at 10:23 AM wrote: > Hi, > Please help me understand the below: > I got this from "The Zoo of Go Functions" > > type Count int > > func (c *Count) Incr

[go-nuts] Go has confusing pointers

2020-06-19 Thread christofccc
Hi, Please help me understand the below: I got this from "The Zoo of Go Functions" type Count int func (c *Count) Incr() int { *c = *c + 1 //why use *c and not just c, based on (c *Count) c is already a pointer? return int(*c) //why cast to int, c is already of type int? } Christof -- You