title: How to include a newline in a C++ macro or how to use C++ templates to do the same?
body: <p>I saw the following question:
  <a href="https://stackoverflow.com/questions/98944/how-to-generate-a-newline-in-a-cpp-macro">How to generate a newline in a cpp macro?</a></p>
  
  <p>Let me give a brief requirement of a need in newline in a C++ preprocessor. Am working on ARM Realview compiler 3.1 on a code which uses embedded assembly code with C++ code.</p>
  
  <pre><code>#define DEFINE_FUNCTION(rtype, op, val) \
      __asm rtype nt_##op(void*) { \   
        str lr, [sp, ##val];bl vThunk_##op;ldr lr, [sp,##val];bx lr; \
      } \
     void vThunk_##op(void*)
  
  DEFINE_FUNCTION(void*, mov_lt, #0x04)
  {
       // do some operation
  }
  </code></pre>
  
  <p>The above macro declares a embedded assembly function which forcefully requires newline between each statements in the function body. </p>
  
  <p>I think this is because the text in the function body is sent blindly to ARM assembler by ARM compiler.</p>
  
  <p>Why C++ preprocessor is still now not supporting multi-line replacements ? and also i cannot use # in the replacement string. for example, for this kind of assembly,</p>
  
  <pre><code>str lr, [sp, #0x04]
  </code></pre>
  
  <p>I tried lots of methods and ways, but nothing really worked out. ARM assembler/compiler is so basic that there is no API like asm volatile in GCC.</p>
  
  <p>DEFINE_FUNCTION macro is used at lots of places, so cannot ignore it also.</p>
  
  <p>So, at final resort thinking about the following solutions:</p>
  
  <ul>
  <li>Using m4 preprocessor instead of C++ preprocesser</li>
  <li>Use C++ templates to somehow achieve this and replace DEFINE_FUNCTION using grep/sed</li>
  </ul>
  
  <p>Can anyone give me pointers or ways to do the above things ? I cannot use any compiler other than ARM Realview compiler 3.1.</p>
  
  <p>I need some expansion like below with new line for,  <code>DEFINE_FUNCTION(void*, mov_lt, #0x04) {}</code>,</p>
  
  <pre><code>__asm void* nt_mov_lt(void*) {   
        str lr, [sp, 0x04];
        bl vThunk_mov_lt;
        ldr lr, [sp,0x04];
        bx lr;
      }
   void vThunk_mov_lt(void*)
   {
       // do something
    }
  </code></pre>