Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>On an x86 architecture (using gcc 3.4.6,) the return value of int functions is stored in the eax register. Floating-point numbers are returned via an XMM register or in ST0. [Edit: Thanks Bastien Leonard!]</p> <p>Void functions simply don't put anything into eax and return.</p> <pre><code>#include &lt;stdio.h&gt; int f1(void) { printf("f1\n"); return 9.0f; } void f2(void) { printf("f2\n"); } double f3(void) { return 10.0; } int main(void) { int x = f1(); f2(); double y = f3(); return 0; } </code></pre> <p>builds with gcc -S to:</p> <pre><code>main: pushl %ebp movl %esp, %ebp subl $24, %esp andl $-16, %esp movl $0, %eax addl $15, %eax addl $15, %eax shrl $4, %eax sall $4, %eax subl %eax, %esp call f1 movl %eax, -4(%ebp) call f2 call f3 fstpl -16(%ebp) movl $0, %eax leave ret .size main, .-main .section .note.GNU-stack,"",@progbits .ident "GCC: (GNU) 3.4.6" </code></pre> <p>with f2 defined:</p> <pre><code>f2: pushl %ebp movl %esp, %ebp subl $8, %esp subl $12, %esp pushl $.LC1 call printf addl $16, %esp leave ret .size f2, .-f2 </code></pre> <p>and f1 defined:</p> <pre><code>f1: pushl %ebp movl %esp, %ebp subl $8, %esp subl $12, %esp pushl $.LC0 call printf addl $16, %esp movl $9, %eax leave ret </code></pre> <p>If other people get different code from different versions of gcc, that would be interesting to see XD (Maybe in other situations int functions return on the stack...)</p> <p>I would imagine that in all implementations, though, a void function simply returns nothing. It either leaves the return registers alone and/or drops nothing on (or into) the stack.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload