C preprocessor: How to create a character literal?
<p>Just out of curiosity, I'd like to know if it is possible to define a macro which can turn its argument into a character literal:</p>

<pre><code> switch(getchar()) {
   case MYMACRO(A): printf("Received A\n"); break;
   case MYMACRO(a): printf("Received a\n"); break;
   case MYMACRO(!): printf("Received an exclamation mark\n"); break;
   default: printf("Neither a nor A nor !\n"); break;
 }
</code></pre>

<p>Two possible solutions off the top of my head:</p>

<p><strong><em>Enumerating all characters</em></strong></p>

<pre><code>#define LITERAL_a 'a'
#define LITERAL_b 'b'
...
#define MYMACRO(x) LITERAL_ ## x
</code></pre>

<p>It doesn't work with <code>MYMACRO(!)</code> because <code>!</code> is not a valid component of a C identifier.</p>

<p><strong><em>Convert the parameter into a string literal</em></strong></p>

<pre><code>#define MYMACRO(x) #x [0]
</code></pre>

<p>It involves a pointer dereference and is invalid in places like a case label.</p>

<p><strong>I'm not asking for a way to "improve" the above switch statement itself.  It's just a toy example.  Repeat.  It's just a toy example.</strong></p>