Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><code>l1[]</code> and <code>l2[]</code> are removed during compiler optimisation because both are <code>local and unused variables</code> (no chance that both variable will be use any where else). </p> <p>you can compile your code with <code>-S</code> option to generate assembly code: and there is no definition for <code>l1[]</code> and <code>l2[]</code> in main not even any where else: </p> <p><sub>input file was <code>x.c</code>, compiled with command <code>gcc -S x.c</code> to generate assembly file <code>x.s</code></sub> </p> <pre><code>main: pushl %ebp movl %esp, %ebp subl $16, %esp movb $28, -4(%ebp) movb $44, -3(%ebp) movb $60, -2(%ebp) movb $76, -1(%ebp) leave ret .size main, .-main .data .type l2.1250, @object .size l2.1250, 4 </code></pre> <p>But you can find definition for <code>g1[] and g2[]</code>. </p> <pre><code> .file "x.c" .globl g1 .data .type g1, @object .size g1, 4 g1: .byte 26 .byte 42 .byte 58 .byte 74 .type g2, @object .size g2, 4 g2: .byte 27 .byte 43 .byte 59 .byte 75 .text .globl main .type main, @function </code></pre> <p><strong>Additionally</strong> , It would be interesting to know if you compile if you compile you code with flag <code>-O3</code> <em>optimisation flag level 3</em> then only definition of <code>g1[]</code> is present. and global static variables(private to the file) are also removed. </p> <p><sub>input file was <code>x.c</code>, compiled with command <code>gcc -S -O3 x.c</code> to generate assembly file <code>x.s</code></sub> </p> <p>below: </p> <pre><code> .file "x.c" .text .p2align 4,,15 .globl main .type main, @function main: pushl %ebp movl %esp, %ebp popl %ebp ret .size main, .-main .globl g1 .data .type g1, @object .size g1, 4 g1: .byte 26 .byte 42 .byte 58 .byte 74 .ident "GCC: (Ubuntu/Linaro 4.4.4-14ubuntu5) 4.4.5" .section .note.GNU-stack,"",@progbits </code></pre> <p><code>g1[]</code> is global data only present, and <code>g2[]</code> is removed in <code>-O3</code>. </p> <p><code>g2[]</code> use defined <code>static unsigned char g2[]</code> so access only within this file and not use so again unused. But <code>g1[]</code> is global it may be useful by other program if other file include it this. And compiler is not allowed to optimisation away global objects. </p> <p>Reference: <a href="https://stackoverflow.com/questions/1229430/how-do-i-prevent-my-unused-global-variables-being-compiled-out">How do I prevent my 'unused' global variables being compiled out?</a> </p> <p>So, this all due to compiler optimisation! </p>
 

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