you are viewing a single comment's thread
view the rest of the comments
[–] 16 points 1 day ago (2 children)

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.

  • source
  • hideshow 4 child comments