<p>I'm quite confident that globally declared variables get allocated (and initialized, if applicable) at program start time.</p>

<pre><code>int globalgarbage;
unsigned int anumber = 42;
</code></pre>

<p>But what about static ones defined within a function?</p>

<pre><code>void doSomething()
{
  static bool globalish = true;
  // ...
}
</code></pre>

<p>When is the space for <code>globalish</code> allocated? I'm guessing when the program starts. But does it get initialized then too? Or is it initialized when <code>doSomething()</code> is first called?</p>

Static variables are allocated inside a code segment -- they are part of the executable image, and so are mapped in already initialized.
Static variables within function scope are treated the same, the scoping is purely a language level construct.
For this reason you are guaranteed that a static variable will be initialized to 0 (unless you specify something else) rather than an undefined value.
There are some other facets to initialization you can take advantage off -- for example shared segments allow different instances of your executable running at once to access the same static variables.
In C++ (globally scoped) static objects have their constructors called as part of the program start up, under the control of the C runtime library.  Under Visual C++ at least the order that objects are initialized in can be controlled by the
init_seg
pragma.