9.2 Variables in Data Memory
Most variables are ultimately positioned into the data memory. The
exceptions are non-auto
variables which are qualified as
const
, which are placed in the program memory space, see 8.9.1 Const Type Qualifier.
Due to the fundamentally different way in which auto
variables and non-auto
variables are allocated memory, they are discussed
separately. To use the C/C++ language terminology, these two groups of variables are those
with automatic storage duration and those with permanent storage duration,
respectively.
Note: The terms “local” and “global” are commonly used to
describe variables, but are not ones defined by the language standard. The term “local
variable” is often taken to mean a variable which has scope inside a function, and “global
variable” is one which has scope throughout the entire program. However, the C/C++ language
has three common scopes: block, file (i.e., internal linkage) and program (i.e., external
linkage), so using only two terms to describe these can be confusing. For example, a
static
variable defined outside a function has scope only in that file,
so it is not globally accessible, but it can be accessed by more than one function inside
that file, so it is not local to any one function either. In terms of memory allocation,
variables are allocated space based on whether it is an auto
or not, hence
the grouping in the following sections.