General Note
The default optimization applied to debug compiled programs doesn't remove variables and loops that from its point of view appear to do nothing. But if you compile with a different optimization or compile to release this may be a problem. For example the for loop:
for(i=0;i<10;i++){};
will be removed as it appears not to do anything. Of course it is being used as a timing element and should be in the program.
There are a number of solutions. You can add:
#pragma GCC optimize ("O0")
to the start of the program to tell the compiler not to optimize or you can declare the loop variable to be volatile:
volatile int i;
for(i=0;i<10;i++){};
A volatile variable is one that can be changed by means outside the program and hence the compiler cannot remove it. In this case i is not actually changed outside of the program but it does stop the compiler changing the meaning of the program.
If you find release programs behaving strangely see if there are time wasting loops that are being optimized out and if so add volatile.
Page 71
the sentence
The system can only operate in equilibrium where the line and the curve intersect – the voltage and current in the resistor have to be the same as the leakage voltage and current.
should say
The system can only operate in equilibrium where the line and the curve intersect – the current in the resistor has to be the same as the leakage current.
That is only the current in the resistor and the output stage have to be same as they are in series.
The voltage adjusts itself across both to make the currents the same.