Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Not replying the question but giving an example of compile time optimization. gcc optimizes the code when asked to do so. The -O (Optimize) option enables optimization in different leves. It can be used as -O1, -O2 and -O3. The gcc man page describes precisely the meaning of each level.</p> <p>The -S option translates C into assembly and saves on .s file.</p> <p>test.c</p> <pre><code>#include &lt;stdio.h&gt; int abc;//Global variable void main() { abc = 3; if(abc == 3) printf("abc will be always 3"); else printf("This will never executed"); } </code></pre> <p><strong>Whitout gcc optimization the two strings appear on the assembly code.</strong></p> <p>$ gcc -S test.c;cat test.s</p> <pre><code> .file "test.c" .comm abc,4,4 .section .rodata .LC0: .string "abc will be always 3" .LC1: .string "This will never executed" .text .globl main .type main, @function main: .LFB0: .cfi_startproc pushq %rbp .cfi_def_cfa_offset 16 .cfi_offset 6, -16 movq %rsp, %rbp .cfi_def_cfa_register 6 movl $3, abc(%rip) movl abc(%rip), %eax cmpl $3, %eax jne .L2 movl $.LC0, %eax movq %rax, %rdi movl $0, %eax call printf jmp .L1 .L2: movl $.LC1, %eax movq %rax, %rdi movl $0, %eax call printf .L1: popq %rbp .cfi_def_cfa 7, 8 ret .cfi_endproc .LFE0: .size main, .-main .ident "GCC: (GNU) 4.6.1 20110908 (Red Hat 4.6.1-9)" .section .note.GNU-stack,"",@progbits </code></pre> <p><strong>Whit gcc level 1 optimization only one string is translated into assembly</strong></p> <p>$ gcc -O1 -S test.c;cat test.s</p> <pre><code> .file "test.c" .section .rodata.str1.1,"aMS",@progbits,1 .LC0: .string "abc will be always 3" .text .globl main .type main, @function main: .LFB11: .cfi_startproc subq $8, %rsp .cfi_def_cfa_offset 16 movl $3, abc(%rip) movl $.LC0, %edi movl $0, %eax call printf addq $8, %rsp .cfi_def_cfa_offset 8 ret .cfi_endproc .LFE11: .size main, .-main .comm abc,4,4 .ident "GCC: (GNU) 4.6.1 20110908 (Red Hat 4.6.1-9)" .section .note.GNU-stack,"",@progbits </code></pre>
    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.
 

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