title: Why does gdb show my code with macros even after I manually run the preprocessor?
body: <p>Sorry if this question is poorly phrased, but it's a weird problem and I'm not sure entirely how to explain it. I wrote some stupid code involving macros that had a stupid error, but even though I solved the problem, gdb didn't help very much. I thought the problem might be in how I wrote the macros (it wasn't), so I used the -E flag so I could inspect the code and debug it without the macros. Then this happened:</p>
  
  <pre><code>/media/sf_Mint-Shared/C $ clang switch.c -E &gt; switch_e.c
  /media/sf_Mint-Shared/C $ clang switch_e.c -g -O0 -o switch
  /media/sf_Mint-Shared/C $ gdb switch
  </code></pre>
  
  <p>[snip]</p>
  
  <pre><code>(gdb) run
  Starting program: /media/sf_Mint-Shared/C/switch 
  Enter your favorite fruit: apple
  
  Program received signal SIGSEGV, Segmentation fault.
  0x00007ffff7b6f2f2 in ?? () from /lib/x86_64-linux-gnu/libc.so.6
  (gdb) l
  6   #define SWITCH(t) strcpy(switch_str, t);
  7   #define CASE(c, d) if (!strcmp(switch_str, (c))) {d} else
  8   #define ELSE(d) {d}
  9   #define ENDSWITCH() switch_str = NULL;
  10  
  11  int main()
  12  {
  13    char fruit[20];
  14  
  15    printf("Enter your favorite fruit: ");
  (gdb) l 26
  21    scanf("%s", fruit);
  22    to_lower(fruit);
  23  
  24    SWITCH(0, fruit)
  25    CASE(0, "apple", puts("Apples are delicious!");)
  26    CASE(0, "pear", puts("Pears are alright");)
  27    CASE(0, "banana", puts("Ew, bananas are gross");)
  28    ELSE(puts("Sorry, I don't know that fruit.");)
  29    ENDSWITCH(0)
  30  
  </code></pre>
  
  <p>In case it isn't obvious, the macros are still present, despite the fact that I compiled the executable from the fully preprocessed source. Here's the (truncated) code that went into the processor:</p>
  
  <pre><code>// Includes truncated
  
  static char *switch_str;
  
  
  
  
  
  
  int main()
  {
    char fruit[20];
  
    printf("Enter your favorite fruit: ");
    scanf("%s", fruit);
  
    strcpy(switch_str, fruit);
    if (!strcmp(switch_str, ("apple"))) {puts("Apples are delicious!");} else
    if (!strcmp(switch_str, ("pear"))) {puts("Pears are alright");} else
    if (!strcmp(switch_str, ("banana"))) {puts("Ew, bananas are gross");} else
    {puts("Sorry, I don't know that fruit.");}
    switch_str = ((void *)0);
  
    return 0;
  }
  </code></pre>
  
  <p>How are the original macros persisting even after preprocessing and how can I debug with them expanded?</p>