Usage of extern keyword and multiple translation units
<p>I am reading Item 4 of Scott Meyer's Effective C++ where he is trying to show an example where  a static non-local object is used across different translation units. He is highlighting the problem whereby the object used in one translation unit does not know if it has been initialised in the other one prior to usage. Its page 30 in the third edition in case anyone has a copy.</p>

<p>The example is such:</p>

<p>One file represents a library:</p>

<pre><code>class FileSystem{
    public:
        std::size_t numDisks() const;
    ....
};

extern FileSystem tfs;
</code></pre>

<p>and in a client file:</p>

<pre><code>class Directory {
    public:
        Directory(some_params);
    ....
};

Directory::Directory(some_params)
{
    ...
    std::size_t disks = tfs.numDisks();
    ...
}
</code></pre>

<p>My two questions are thus:</p>

<p>1) If the client code needs to use <code>tfs</code>, then there will be some sort of include statement. Therefore surely this code is all in one translation unit? I do not see how you could refer to code which is in a different translation unit? Surely a program is always one translation unit?</p>

<p>2) If the client code included FileSystem.h would the line <code>extern FileSystem tfs;</code> be sufficient for the client code to call tfs (I appreciate there could be a run-time issue with initialisation, I am just talking about compile-time scope)?</p>

<p><strong>EDIT to Q1</strong></p>

<p>The book says these two pieces of code are in separate translation units. How could the client code use the variable <code>tfs</code>, knowing they're in separate translation units??</p>
