I need to make some simple character modifications on compile time, for example instead of:
char text[] = "test text";
I want to be able to write:
char text[] = _MODIFY("test text", 10);
And I want it to be preprocessed as:
char text[] = {116^10,101^10,115^10,116^10,32^10,116^10,101^10,120^10,116^10,0 };
where numbers are ASCII codes XORed with constant. How to define _MODIFY macro preprocessor?
The transformation you were originally describing is exactly, what the compiler does:
char text[] = "test text";is just a shorthand forchar text[] = {116, 101, 115, 116, 32, 116, 101, 120, 116, 0 };.I don't think, that the CPP is capable of doing that on the string definition, because it works string-based not token-based. So it has now clue, what it parameters you give to a macro, it just performs text expansion.
What you can do, is this:
This works around the limitations, that macro expansion isn't recursive by deferring evaluation of macro expansion until EXPAND.
Note, that this limits macro expansion to some depth. If you start seeing your macros again, higher the number of EXPAND_ calls.
See also: Recursive macros via __VA_OPT__
Alternatively, you might achieve it with your build system. Either you are modifying the source, or defining a macro with -D... .