Meanwhile `static inline` is easy. It requires no additional effort. And, as I stated above, it is actually redundant.
Yes.
Human programmers often use "
static" alone for internal functions, and "
static inline" for macro-like accessor functions.
The compiler treats the two exactly the same, but for us humans, the distinction can be useful. Consider it a "coding style" choice.
As far as I know, the distinction originates from
GCC from a couple of decades ago, and how its implementation used to differ from ISO C99 – the related topic
"An Inline Function is As Fast As a Macro" used to cause a bit of contention then. Also, when typical/common warnings were enabled, GCC used to emit a warning when a
static function was not used, but be silent when a
static inline function was not used. Nowadays, even GCC treats "
static" and "
static inline" the same, so the difference only matters to (some) human programmers.
I sometimes point this kind of stuff out, because in my opinion, "coding style" is and should not be about how pretty the code looks, but something that reduces the cognitive load of working with the code, so that humans with limited brainpower like myself can spend it on the important things, and not waste on superfluous stuff. Nowadays, I'm investigating whether using descriptive preprocessor macros (like say
ACCESSOR or
INTERNAL) instead of the abovementioned static/static inline works better.
Every access to a volatile variable is part of the observable behavior of the program. This is out of bounds for the optimizer. The optimizer is not permitted to change the observable behavior in any way. The optimizer is not allowed to eliminate volatile accesses. The optimizer is not allowed to reorder volatile accesses.
I do believe this description should help those unfamiliar with
volatile.
Personally, I might follow up with explaining how the optimizer can eliminate non-volatile variable accesses by "caching" or remembering the value from the previous access, if it can determine that the value is not/will not be modified as part of the program flow. (Needs better wording, though.)
This stuff is not hard or complicated; it is just that many programmers have an incorrect/partial understanding of what and how the compiler does what it does and per what rules, and
volatile is one of the tripping points where it shows. Better understanding the model and/or rules, like how the optimizer does what it does, immediately leads to better understanding of
volatile as well. So, the underlying problem is definitely not that they misunderstand
volatile per se; it is the partial or incorrect understanding of how the compiler (including the optimizer in it) do what they do and based on what rules, and how
volatile is hard/impossible to reconcile with such a misunderstanding. Especially when they've heard claims like "C is just a macro assembler" and let those shape their understanding.