dont_reuse_strings
is enabled. This option can cause code bloat in programs that overuse inline functions. Default is off.
34.2 dont_reuse_strings
Controls whether or not to store identical character string literals separately in object code.
Syntax
#pragma dont_reuse_strings on | off | reset
Remarks
Normally, C and C++ programs should not modify character string literals. Enable this pragma if your source code follows the unconventional practice of modifying them.
If you enable this pragma, the compiler separately stores identical occurrences of character string literals in a source file.
If this pragma is disabled, the compiler stores a single instance of identical string literals in a source file. The compiler reduces the size of the object code it generates for a file if the source file has identical string literals.
The compiler always stores a separate instance of a string literal that is used to initialize a character array.
Listing 34-1 on page 520 shows an example.
Although the source code contains 3 identical string literals,
"cat"
, the compiler will generate 2 instances of the string in object code. The compiler will initialize str1
and str2 to point to the first instance of the string and will initialize str3
to contain the second instance of the string.
Using str2
to modify the string it points to also modifies the string that str1
points to. The array str3
may be safely used to modify the string it points to without inadvertently changing any other strings.
By default, this pragma is off
.
Listing 34-1. Reusing string literals
#pragma dont_reuse_strings off void strchange(void)
{
const char* str1 = "cat";
char* str2 = "cat";
char str3[] = "cat";
CodeWarrior Development Studio for Advanced Packet Processing Build Tools Reference Manual, Rev.
10.2, 01/2016
520 Freescale Semiconductor, Inc.