Rod said:
Rod said:
is a simple solution:
#define _S(x) #x
#define _T(a,b,c,d,e,f) _S(a ## b ## c ## d ## e ## f)
#define CRYPT(a,b,c,d,e,f) _T(a,b,c,d,e,f)
/* define aliases for each letter, limited to _A-Za-z0-9 */
/* or you can use specific char's, say '!', directly in txt1 */
#define _CK A
#define _Cu z
#define _Cn y
#define _Cg q
#define _CF p
int main(void)
{
char txt1[]=CRYPT(_CK,_Cu,_Cn,_Cg,_CF,_Cu);
Why don't you concatenate the _C prefix in the CRYPT macro?
#define CRYPT(a,b,c,d,e,f) _T(_C##a,_C##b,_C##c,_C##d,_C##e,_C##f)
Because it doesn't work... at least with the compilers I use.
Oops. I forgot to add has the intermediate expansion macro:
#define _T0(a,b,c,d,e,f) _T(a,b,c,d,e,f)
#define CRYPT(a,b,c,d,e,f) _T0(_C##a,_C##b,_C##c,_C##d,_C##e,_C##f)
now this should work.
char txt1[]=CRYPT(K,u,n,g,F,u);
int main(void)
{
char txt1[]="Azyqpz";
}
Do you mean something like ;-) :
/* concatenate LIST1 and LIST2 */
#define cos_PPL_CAT(LIST1,LIST2) \
(cos_PP_ADD(cos_PP_LEN(LIST1),cos_PP_LEN(LIST2)), \
(cos_PP_IF(cos_PP_AND(cos_PP_LEN(LIST1),cos_PP_LEN(LIST2)), \
cos_PP_PAIR,cos_PP_CONS) \
(cos_PPL_TUPLE(LIST1),cos_PPL_TUPLE(LIST2))))
/* concatenate the LIST elements */
#define cos_PPL_ECAT(LIST) \
cos_PPL_APPLY(cos_PP_DECR(cos_PP_LEN(LIST)),cos_PPL_ECAT_,LIST)
#define cos_PPL_ECAT_(LIST) cos_PPL_CAT( \
(1, (cos_PP_CAT(cos_PPL_ELEM(0,LIST),cos_PPL_ELEM(1,LIST)))), \
cos_PPL_TAIL(cos_PP_SUB(cos_PP_LEN(LIST),2),LIST))
IMO, limitations of the preprocessor to do text replacement. It was very
difficult to come up with an example that worked the same way for both DJGPP
and OW. Things that worked on one didn't work on the other and vice versa.
It is clear that porting code to a non ISO C99 preprocessor can be a
nightmare. But in that case, I just throw away the cpp and take a
compliant one (e.g. ucpp).
The preprocessor isn't intended to be a full string library capable of doing
encryption. In a few lines of mostly non-preprocessor C code, he could do
everything he wants without much hassle.
Once you have a "user-friendly" package of macros to deal with lists of
tokens, much can be done easily, especially for generating C code.
a+, ld.