Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The compiled program no longer has any knowledge about <code>struct LinkedNode</code> or field named <code>next_node</code>, or anything like that. Any names are completely gone from the compiled program. The compiled program operates in terms of numerical values, which can play roles of memory addresses, offsets, indices and so on.</p> <p>In your example, when you read <code>mynode-&gt;next_node</code> in the source code of your program, it is compiled into machine code that simply reads the 4-byte numerical value from some reserved memory location (known as variable <code>mynode</code> in your source code), adds 4 to it (which is offset of the <code>next_node</code> field) and reads the 4-byte value at the resultant address (which is <code>mynode-&gt;next_node</code>). This code, as you can see, operates in terms of integer values - addresses, sizes and offsets. It does not care about any names, like <code>LinkedNode</code> or <code>next_node</code>. It does not care whether the memory is allocated and/or freed. It does not care whether any of these accesses are legal or not. </p> <p>(The constant 4 I repeatedly use in the above example is specific for 32-bit platforms. On 64-bit platforms it would be replaced by 8 in most (or all) instances.)</p> <p>If an attempt is made to read memory that has been freed, these accesses might crash your program. Or they might not. It is a matter of pure luck. As far as the language is concerned, the behavior is undefined.</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