Skip to content

Misleading equivalence between global and static variables #4819

Description

@donallen1942
  • I have searched open and closed issues and pull requests for duplicates, using these search terms:

  • I have checked the latest main branch to see if this has already been fixed, in this file:

URL to the section(s) of the book with this problem:
https://doc.rust-lang.org/book/ch20-01-unsafe-rust.html?search=static%20variables
Description of the problem:
Section 20.1 states that "In Rust, global variables are called static variables." This strongly suggests that global variables and static variables are one and the same, which is not true. Global variables are static variables (where static indicates that they live as long as the application) that have global lexical scope. The language supports the definition of static variables that have local scope, e.g., the scope of a function, similar to static variables in C. The book does not discuss this.
Suggested fix:
Describe global variables as static variables (where static indicates that they live as long as the application) that have global lexical scope. And indicate that static variables may be defined that have local scope.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions