title: C preprocessor macro specialisation based on an argument
body: <p>Is it possible to have one macro expanded differently for one specific argument value and differently for all other arguments?</p>
  
  <p>Say I define a current user:</p>
  
  <pre><code>#define CURRENT_USER john_smith
  </code></pre>
  
  <p>What I want to be able to do is to have a macro that will be <em>expanded</em> differently if user passed matches <code>CURRENT_USER</code>. Mind you that I don't know all possible user a priori. The most basic case:</p>
  
  <pre><code>#define IS_CURRENT_USER(user)                   \
      /* this is not valid preprocessor macro */  \
      #if user == CURRENT_USER                    \
          1                                       \
      #else                                       \
          0                                       \
      #endif                                      
  </code></pre>
  
  <p>With macro like that every other macro relying on the username could be done following way:</p>
  
  <pre><code>#define SOME_USER_SPECIFIC_MACRO(user) SOME_USER_SPECIFIC_MACRO_SWITCH_1(IS_CURRENT_USER(user))
  
  #define SOME_USER_SPECIFIC_MACRO_SWITCH_1(switch)   SOME_USER_SPECIFIC_MACRO_SWITCH_2(switch) // expand switch ...
  #define SOME_USER_SPECIFIC_MACRO_SWITCH_2(switch)   SOME_USER_SPECIFIC_MACRO_##switch         // ... and select specific case
  
  #define SOME_USER_SPECIFIC_MACRO_0  ... // not current user
  #define SOME_USER_SPECIFIC_MACRO_1  ... // current user
  </code></pre>
  
  <p>Is this possible?</p>
  
  <p>EDIT: Let me clarify. Say each programmer defines different <code>CURRENT_USER</code> in their config header. I want user specific macros to exand to something meaningful if and only if their <code>user</code> argument matches <code>CURRENT_USER</code>. As I would like those macros to contain <code>_pragma</code>s it can't be runtime check (as proposed in some anwsers below).</p>
  
  <p>EDIT: Again, clarification. Say there's macro to disable optimisation of some sections of code:</p>
  
  <pre><code>#define TURN_OPTIMISATION_OFF __pragma optimize("", off)
  </code></pre>
  
  <p>Some programmers want to turn optimisation off for different sections of code but not all at one time. What I'd like is to have a macro:</p>
  
  <pre><code>#define TURN_OPTIMISATION_OFF(user) /* magic */
  </code></pre>
  
  <p>That will match <code>user</code> argument against <code>CURRENT_USER</code> macro, taken from per-programmer config file. If the user matches macro is expanded into pragma. If not, to nothing.</p>