My understanding is that global variables are loaded or stored for each statement they are used at least once (implicit "volatile" for globals). And on contrast local variables are free for any optimisations, also throughout several statements or may be even optimised away.
My question now is, which variables are 'global' and which are 'local' in the meaning of memory barriers?
Variables inside functions or procedures are local. Global variables are defined outside function or procedure, those, the variables of the units and the body of the main program. Class or object fields are often called member variables. They behave as global, because they are available in different functions, but as local ones, because only used in the context of a class variable. This is the
scope property.
Static is the
lifetime of variable (until the end of the program). For example, all global variables. Or typed consts (local). Or class variables.
The absolute variable has the same properties as the variable that it refers to. Those, can be global, local, static, etc.
Volatile are variables in the C language that compiler must exclude from optimization, because their value can change outside the executed code. There is no corresponding directive in FPC. In C volatile can be static or not, global or local.
Global, local, member, static, absolute variables can be optimized by the compiler (now or in the future). To exclude a variable from optimization, replace it with a function call.