Our company's static analysis tool is stating that there are duplicated strings (text literals). The issue is that they are spread across many translation units (source files).
For example, the string "NULL console pointer" exists 1 time in module_a.c, 5 times in module_b.c and 1 time in module_f.c.
We also have coding guidelines that state there is to be no global variables.
We are to prefer to have no variables in header files.
Our platform is an embedded system, so consolidation of constant text will provide room for other purposes (and make the program load faster). In other words, there should only be one instance of the text literal.
So, what is an efficient design or architecture for consolidating constant text literals across multiple translation units?
Is there a length limit where duplication is not worth consolidating (such as the string "rn"?
We would prefer solutions that are performance efficient, such as preferring direct access over calling a getter function.
(Note: at this time, the text does not need to be translated into multiple languages.)
Languages: C and C++ (The code base is more C language than C++).
Processor: ARM Cortex A8
Platform: Embedded system, safety and quality and performance critical (medical device).
Compilers: IAR Embedded Workbench (for ARM processor).
Edit 1: Linker Not Consolidating
I scanned the BIN file and it does contain multiple instances of "NULL console pointer".
The linker has the option "Merge duplicate section" and I checked that. The binary still contains duplicates.
Aucun commentaire:
Enregistrer un commentaire