Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<h1>How to find it out</h1> <p>That's the address of a label and it's a feature specific to <a href="http://gcc.gnu.org/onlinedocs/gcc/Labels-as-Values.html">GCC</a>.</p> <pre><code>int main(void) { void* startp; s: startp = &amp;&amp;s; printf("the assignment above starts at address %p\n", startp); return 0; } </code></pre> <p>You could have figured it out yourself by testing:</p> <pre><code>int main(void) { void* startp; int a; startp = &amp;&amp;a; printf("startp=%p\n", startp); return 0; } </code></pre> <p>In which case GCC says:</p> <blockquote> <p>error: label ‘a’ used but not defined</p> </blockquote> <h1>Under the hood - assembly</h1> <p>You need to know assembler to really understand this, but I'll try to explain you what an address of a label means.</p> <p>After the OS loads the .exe file from the disk, a component of the operating system called "the loader" (windows has the "PE Loader", linux has "ELF loader" or maybe even others, if they're compiled in the kernel), it does a "virtualization" of that program, turning it into a process.</p> <p>This process thinks it is the only one in RAM and it has access to the entire RAM (that is, 0x00000000-0xFFFFFFFF on a 32-bit machine).</p> <p>(the above is just a short overwiew of what's happenning, you really need to learn assembly to understand it fully, so bear with me)</p> <p>Now, the label in a source code is basically an address. "goto label;" does nothing else than a jump to that address (think about the <a href="http://en.wikipedia.org/wiki/Program_counter">instruction pointer</a> in assembly). This label stores this RAM address, and that's how you can find out that address.</p> <p>After you've learned ASM, you'll realize that that address points to a instruction within the <code>.text</code> section of the executable. The <code>.text</code> section is the one which holds you program's (binary) code to be executed.</p> <p>You can inspect this with:</p> <blockquote> <p>objdump -x a.out</p> </blockquote> <h1>A practical example</h1> <p>As described in <a href="http://gcc.gnu.org/onlinedocs/gcc/Labels-as-Values.html">GCC</a>, you can use this to initialize a jump table. Some <a href="http://en.wikipedia.org/wiki/Lexical_analysis">scanner generators</a> like <a href="http://re2c.org/">re2c</a> (see the <code>-g</code> parameter) use that to generate more compact scanners. Maybe there's even a <a href="http://en.wikipedia.org/wiki/Compiler-compiler">parser generator</a> employing the same technique.</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