You cannot do easily that, but you could edit every source file to change every occurrence of your strings. If using emacs
as your editor, you could code some Emacs Lisp code to automate that editing.
Of course, you can generate your C code from something else, e.g. using some other preprocessor (gpp
, m4
) and or some (e.g. awk
) script.
You might consider adopting the convention that every such string is used in unique macro, e.g. MY_STRANGE_STRING("abc")
instead of simply "abc"
; then you might use some preprocessor macro tricks -concatanation, __LINE__
, perhaps stringification- .... (perhaps using gpp preprocessor to generate some header, etc...)
A possibility could be to process your source twice. First by some gpp
or m4
preprocessing which would transform MY_STRANGE_STRING("abc")
occurring at line 123 into a #define MY_STRING_CONSTANT_123 "cde"
in some generated header. Then the C compiler would use ordinary preprocessing tricks to get that.
You could also transform the preprocessed form of your source code by an ad-hoc tool or script.
If compiling with recent GCC (specifically) you could use MELT to customize your compiler to do such tricks. You'll then insert some optimization passes to do the transformation. You might define the MY_STRANGE_STRING
to be your application specific __my_strange_string_builtin
and add that additional builtin into GCC, etc...
Notice that you probably don't want to transform every literal strings (e.g. you probably don't want to transform the literal control string of most fprintf
calls..., or the expansion of __FILE__
or __DATE__
which is happening in some system macros, e.g. assert
), but only some of them.
I cannot help more, since you don't motivate your question.