On Wednesday, 20 November 2019 17:55:59 UTC, Ian Lance Taylor wrote:
>
> The other kind of answer is that if a function returns a pointer to a 
> struct, a value of type *employee, then it's normal for that something 
> else to have a copy of that pointer, perhaps some data structure or 
> global variable.  In your simple example that is the global variable 
> "dilbert".  So it makes sense to permit setting a field of the result 
> of calling getEmployee(), a value of type *employee, as setting that 
> field will change the global variable "dilbert".  But when 
> getEmployee() does not return a pointer, but just returns a value of 
> type "employee", then that is a copy of the value in the global 
> variable.  Changing a field in that copy won't change anything.  The 
> assignment will be made, and then the result will be discarded.  Since 
> that operation is useless, the language does not permit it. 
>

 Hi Ian and thanks for your prompt reply. This is exactly the kind of 
explanation that I was looking for and it makes complete sense now.

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/7fb82fec-9430-4c5e-8005-ce86cda91921%40googlegroups.com.

Reply via email to