title: Assembler templates, asmSymbolicName and "error: expected string-literal"
body: <p>I'm trying to use GCC's extended ASM like Microsoft's assembler. Under Microsoft's MASM, we can do the following, where <code>__FUNC</code> is a C variable:</p>
  
  <pre><code>mov eax, __FUNC
  </code></pre>
  
  <p>According to <a href="https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html" rel="nofollow">Extended Asm - Assembler Instructions with C Expression Operands</a>, § 6.44.3.1 <em>Input Operands</em>:</p>
  
  <blockquote>
    <p>Operands are separated by commas. Each operand has this format:</p>
  
  <pre><code> [ [asmSymbolicName] ] constraint (cexpression)
  </code></pre>
    
    <p>asmSymbolicName</p>
    
    <p>&nbsp;&nbsp;&nbsp;&nbsp; Specifies a symbolic name for the operand. Reference the name in the assembler template by enclosing it in square brackets (i.e. ‘%[Value]’). The scope of the name is the asm statement that contains the definition. Any valid C variable name is acceptable, including names already defined in the surrounding code...</p>
  </blockquote>
  
  <p>When I try and use it in code:</p>
  
  <pre><code>unsigned int func = 1;
  ...
  
  __asm__ __volatile__ (
    "movl %[__FUNC], %%eax"
    ...
  
    :
    : __FUNC "" (func)
  );
  </code></pre>
  
  <p>It results in:</p>
  
  <pre><code>cpu.cpp:148:5: error: expected string-literal before ‘__FUNC’
   : __FUNC "" (func)
     ^
  cpu.cpp:148:5: error: expected ‘(’ before ‘__FUNC’
  cpu.cpp:148:17: error: ‘__FUNC’ was not declared in this scope
  ...
  </code></pre>
  
  <p>The best I can tell, I am using <code>__FUNC</code> according to the manual and its description of <code>asmSymbolicName</code>. But obviously I am not since there's an error.</p>
  
  <p>What am I doing wrong?</p>
  
  <hr>
  
  <p>I also tried the following because the manual told me I could use variable names in surrounding code, but it did not work either:</p>
  
  <pre><code>"movl %[func], %%eax"
  ...
  
  :
  : func "" (func)
  </code></pre>
  
  <p>And:</p>
  
  <pre><code>"movl %[func], %%eax"
  ...
  
  :
  : func (func)
  ...
  </code></pre>