C (Preprocessor): How to concatenate/append substitution string -


i define exceptions on command line:

-dexception_1=\"first\" -dexception_2=\"second\" -dexception_3=\"third\" 

which check against string:

except = 0; #ifdef exception_1 if (! strcmp(exception_1, mystring)) {  except = 1; } #endif #ifdef exception_2 if (! strcmp(exception_2, mystring)) {  except = 1; } #endif #ifdef exception_3 if (! strcmp(exception_3, mystring)) {  except = 1; } #endif if (except == 1) {  // } else {  // else } 

needless say, while works, quite ugly, inflexible , causes redundancy in code.

is there way append string preprocessor macro variable?

i (the problem of course #append not exist):

#ifdef exception_1 #append exceptions if (! strcmp(exception_1, mystring)) {  except = 1; } #ifdef exception_2 #append exceptions if (! strcmp(exception_2, mystring)) {  except = 1; } #ifdef exception_3 #append exceptions if (! strcmp(exception_3, mystring)) {  except = 1; } 

then use exceptions in code , work possible permutations of exceptions.

in other words want append string macro variable - possible?

you can have chains of defines, won't better:

#ifdef exception_1  #define exceptions1 if (! strcmp(exception_1, mystring)) {  except = 1; } #else #define exceptions1 #endif  #ifdef exception_2 #define exceptions2 exceptions1 if (! strcmp(exception_2, mystring)) {  except = 1; } #else #define exceptions2 exceptions1  #endif  // etc 

again, not better.

and really shouldn't define macros open if's. allows weird interactions if(cond) exceptions1 else cout<<"error"; -- won't expect because exceptions1 plain if , gobble else branch.

the typical way of writing macros code blocks wrap whole thing in do{...}while(0) (note no ending ;).


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -