title: Concatenate int to string using C Preprocessor
body: <p>I'm trying to figure out how I can concatenate a <code>#define</code>'d int to a <code>#define</code>'d string using the <strong>C</strong> Preprocessor.  My compiler is GCC 4.1 on CentOS 5.  The solution should also work for MinGW.</p>
  
  <p>I'd like to append a version number onto a string, but the only way I can get it to work is to make a copy of the version number defines as strings.</p>
  
  <p>The closest thing I could find was a method of quoting macro arguments, but it doesn't work for <code>#define</code>s</p>
  
  <p>This is does not work.</p>
  
  <pre><code>#define MAJOR_VER 2
  #define MINOR_VER 6
  #define MY_FILE "/home/user/.myapp" #MAJOR_VER #MINOR_VER
  </code></pre>
  
  <p>It doesn't work without the <code>#</code>s either because the values are numbers and it would expand to <code>"/home/user/.myapp" 2 6</code>, which isn't valid <strong>C</strong>.</p>
  
  <p>This does work, but I don't like having copies of the version defines because I do need them as numbers as well.</p>
  
  <pre><code>#define MAJOR_VER 2
  #define MINOR_VER 6
  #define MAJOR_VER_STR "2"
  #define MINOR_VER_STR "6"
  #define MY_FILE "/home/user/.myapp" MAJOR_VER_STRING MINOR_VER_STRING
  </code></pre>