My understanding is there is no reference to 21,000,000 anywhere in the code.
The "limit" is simply an enforcement of what subsidy can be included in a block (which is based on the block's height) and be considered valid by other nodes. Since the subsidy on each block must follow a required decrease the total # of coins that will be minted can be calculated.
All values are stored as 64 bit integers in satoshis (1E-8 BTC).
The initial subsidy is 5,000,000,000 (50 BTC).
The subsidy is right shifted once for every 210,000 blocks in height.
At block height 210,000 a valid node will reduce the subsidy to 2,500,000,000 (25 BTC). Any node that doesn't will have their block rejected by other nodes as invalid.
So at block 6,720,000 the subsidy will be right shifted from 2 satoshi to 1 satoshi.
At block 7,140,000 the subsidy will be right shifted from 1 satoshi to 0 satoshi and no more coins will be minted.
Any block after 7,140,000 with a subsidy of any amount will be considered invalid by other nodes.
If you add up all the block rewards for the first 7,140,000 blocks it adds up to 21M BTC (2,100,000,000,000,000 discrete units).
Actually unless my understanding is incorrect there will never be 21M coins. Due to truncation of some rewards there will be exactly 2,099,999,997,690,000 satoshis mined ( 20,999,999.9769 BTC).