declaring multiple variables is less error-prone than in C. In C, the following declares x to be a pointer, but (surprisingly at first!) y to be a normal integer:
int* x, y;
Whereas the equivalent in Go does what you’d expect, declaring both to be pointers:
var x, y *int
I don’t think this is a related at all. C could have easily decided that the definition makes both x and y pointers. They just decided not to so that you can declare more variables on one line by being able to do int x, *y, **z, .... It is more flexible.
Similarly that Go line could have been parsed like var x, (y*) int if they wanted to. They just made a different choice.
I don’t think this is a related at all. C could have easily decided that the definition makes both
xandypointers. They just decided not to so that you can declare more variables on one line by being able to doint x, *y, **z, .... It is more flexible.Similarly that Go line could have been parsed like
var x, (y*) intif they wanted to. They just made a different choice.That’s why you write
int *x, y, **z;
C doesn’t write like “x is an int-pointer”, rather it says “dereferencing x will get you an int”.