When defining inline variables in .cpp source file, for example by including a header, gcc generates code for guards + initialization of the variables in each .cpp source. Even if the variables are not used anywhere in the .cpp.
Instructions generated by clang are not as clear whether there is the same overhead.
Compile Explorer example.
The overhead results in significant code size increase (with multiple variables in heavily used header), which may be important for embedded development. Using extern does not have the same penalty, but requires definition in a separate source file.
Questions:
- Is this the expected behavior?
- Does clang behave the same, but hidden?
- Can this be avoided while still using
inlineand notextern?