Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Theoretically, the answer is <strong>"it's implementation dependent"</strong>. Each C compiler decides the best approach to take -- as long as it exhibits the correct behavior, it doesn't really matter how you got there.</p> <p>Practically speaking, <strong>you probably won't see a reference to variable names in a compiled program</strong>. That's because the processor doesn't need to know or care about variable names you've assigned in order to execute your program. It operates on a much lower level: it simply needs to understand which instructions to execute and in which order. Therefore, including this information is an superfluous extravagance that would simply inflate the size of your program.</p> <p>There are three basic cases, which I'll enumerate below. I'll also describe the behavior of what a typical compiler would probably do, although remember that it's implementation-dependent and in general compilers are allowed to do whatever they want as long as they exhibit the correct standard behavior.</p> <ul> <li><p>For local variables, as part of the compilation process, the compiler replaces each variable name (e.g. "int foo;") with a reference to the appropriate memory allocated for that variable ("memory address 0x482c"). Assignments or references to this value can typically just refer to the appropriate address.</p></li> <li><p>For non-local variables, the compiler performs additional resolution to determine how to discover, but it's usually still not storing the name of the variable or function directly.</p></li> <li><p>For things that aren't variables at all (structs, methods, etc.), the compiler performs different resolution steps and optimizations based on decisions it's made and parameters that have been set. But here, too, it doesn't store the name of the variable or function; it's just replacing it with the appropriate references.</p></li> </ul> <p>There are cases where it's useful to include variable names in the compiler's output, like when you're debugging. In those cases, a <em>debugging symbol table</em> is created. This is a way to map <em>addresses</em> to <em>names</em> that are meaningful for humans, so that when something crashes, you can see "Stacktrace: function foo() ..." instead of "Stacktrace: Memory address 0x4572 ...".</p> <p>In languages with metaprogramming capabilities, like C#, Ruby, or Java, the <em>names</em> often become part of the metadata that's stored along with the object, rather than just replacing each reference with a lookup on a memory address. That metadata comes in handy when you want to do certain neat tricks that are nigh-impossible in C at runtime, like asking "which objects in this collection have a field named <code>foo</code>?".</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