title: GCC function name conflict
body: <p>I was having some problems with a sample code i was testing, since my abs function was not returning the correct result. abs(-2) was outputing -2 (this, by the way, is suposed to be the absolute value function, if that was unclear)</p>
  
  <p>After getting a bit desperate, i eventually had the following code</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  unsigned int abs(int x) {
      return 1;
  }
  
  int main() {
      printf("%d\n", abs(-2));
      return 0;
  }
  </code></pre>
  
  <p>This does nothing useful but it serves to show my problem. This was outputing -2, when it was expected to output 1.</p>
  
  <p>if i change the function name to something else (abs2 for example), the result is now correct. Also, if i change it to receive two arguments instead of one, it also fixes the problem.</p>
  
  <p>My obvious guess: a conflict with the standart abs function. But this still doesn't explain why the output is -2 (it should be 2, if using the standart abs function). I tried checking the assembly output of both versions (with the function named abs and abs2)</p>
  
  <p>Here's the diff output for both assemblys:</p>
  
  <pre><code>23,25c23,25
  &lt; .globl abs
  &lt;   .type   abs, @function
  &lt; abs:
  ---
  &gt; .globl abs2
  &gt;   .type   abs2, @function
  &gt; abs2:
  54c54
  &lt;   .size   abs, .-abs
  ---
  &gt;   .size   abs2, .-abs2
  71c71,74
  &lt;   movl    -4(%rbp), %edx
  ---
  &gt;   movl    -4(%rbp), %eax
  &gt;   movl    %eax, %edi
  &gt;   call    abs2
  &gt;   movl    %eax, %edx
  </code></pre>
  
  <p>From what i understand, the first version (where the function is named abs) is simply discarding the function call, thus using the parameter x instead of abs(x)</p>
  
  <p>So to sum up: why does this happen, especially since i couldn't find a way to get any sort of warning or error about this.</p>
  
  <p>Tested on Debian Squeeze, ggc 4.4.5, and also on gcc 4.1.2</p>