5.3.9.5 Persistent Type Qualifier
The __persistent
type qualifier is used to indicate that
objects with static storage duration should not be cleared by the runtime startup code, by
having them stored in a different area of memory to other objects.
By default, C objects with static storage duration that are not explicitly
initialized are cleared on startup. This is consistent with the definition of the C
language. However, there are occasions where it is desirable for the content of some
objects to be preserved across a Reset. The __persistent
type qualifier
can be used with these objects to indicate this requirement.
Any object that needs to be persistent cannot be assigned an initial value when defined. A
warning will be issued if you use the __persistent
qualifier with an
object that is assigned an initial value, and for that object, the qualifier will be
ignored.
static
local
object, intvar
, is not cleared at
startup:void test(void)
{
static __persistent int intvar; /* locals must be static to be persistent */
// ...
}