Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spec: term "variable" used inconsistently #8496

Closed
mdempsky opened this issue Aug 8, 2014 · 5 comments
Closed

spec: term "variable" used inconsistently #8496

mdempsky opened this issue Aug 8, 2014 · 5 comments

Comments

@mdempsky
Copy link
Member

mdempsky commented Aug 8, 2014

This might be a bit overly pedantic, but the Go spec seems to imply "variable"
only means objects declared with "variable declarations" and "short
variable declarations" as in

    var x int
    y := 7

For example, see the definition of addressable where it's stated:

    """The operand must be addressable, that is, either a variable, pointer indirection, or slice indexing operation; or a field selector of an addressable struct operand; or an array indexing operation of an addressable array."""

Or how the definitions of array type and struct type avoid the word variable:

    """An array is a numbered sequence of elements of a single type, called the element type."""

    """A struct is a sequence of named elements, called fields, each of which has a name and a type."""

It seems reasonable to infer from that wording then that struct fields and array
elements are *not* variables.  However, if that were the case, it would cause problems
with code like this:

    var x [2]int
    p, q := &x[0], &x[1]
    if p == q { ... }

Pointer types are defined as "A pointer type denotes the set of all pointers to
*variables* of a given type", but x[0] and x[1] are not variables, so we wouldn't
be able to take pointers to those array elements.

Also, equality on pointers is defined as "Two pointer values are equal if they
point to the same *variable* or if both have value nil."  In the above code, p and
q point *into* the same variable, but to different elements within that variable.
@ianlancetaylor
Copy link
Contributor

Comment 1:

Labels changed: added repo-main, release-none.

Owner changed to @griesemer.

Status changed to Accepted.

@gopherbot
Copy link

Comment 2:

CL https://golang.org/cl/148580043 mentions this issue.

@griesemer
Copy link
Contributor

Comment 3:

This issue was closed by revision 6962c15.

Status changed to Fixed.

@gopherbot
Copy link

Comment 4:

I can't read "A variable declaration or, for function parameters and results, the
signature of a function declaration or function literal reserves storage for a named
variable." in any way that would make sense. Function declarations don't reserve storage
for the parameters; calling the function does. Otherwise, the function wouldn't be
reentrant.

@griesemer
Copy link
Contributor

Comment 5:

"reserve" as in making the plan for future allocation.
If you have a better formulation w/o being overly pedantic, please send it to me.

@golang golang locked and limited conversation to collaborators Jun 25, 2016
wheatman pushed a commit to wheatman/go-akaros that referenced this issue Jun 25, 2018
Fixes golang#8496.

LGTM=rsc, r, iant
R=r, rsc, iant, ken
CC=golang-codereviews
https://golang.org/cl/148580043
wheatman pushed a commit to wheatman/go-akaros that referenced this issue Jun 26, 2018
Fixes golang#8496.

LGTM=rsc, r, iant
R=r, rsc, iant, ken
CC=golang-codereviews
https://golang.org/cl/148580043
wheatman pushed a commit to wheatman/go-akaros that referenced this issue Jul 9, 2018
Fixes golang#8496.

LGTM=rsc, r, iant
R=r, rsc, iant, ken
CC=golang-codereviews
https://golang.org/cl/148580043
wheatman pushed a commit to wheatman/go-akaros that referenced this issue Jul 30, 2018
Fixes golang#8496.

LGTM=rsc, r, iant
R=r, rsc, iant, ken
CC=golang-codereviews
https://golang.org/cl/148580043
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants