Controls whether or not to store identical character string literals separately in object code.
#pragma dont_reuse_strings on | off | reset
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. The code listed below 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.
#pragma dont_reuse_strings off void strchange(void) { const char* str1 = "cat"; char* str2 = "cat"; char str3[] = "cat"; *str2 = 'h'; /* str1 and str2 point to "hat"! */ str3[0] = 'b'; /* OK: str3 contains "bat", *str1 and *str2 unchanged. }