title: Initializing custom output stream before main
body: <p>Say I want to write an API (for C/Linux) that offers a customized output stream, like <code>stdout</code> but mine should be called <code>not_stdout</code>. So I could demand that people using my API always begin their main program by calling a function <code>init_the_stream()</code> that initializes <code>extern FILE* not_stdout</code>. </p>
  
  <p>But what I'd really like is for my stream to be initialized prior to <code>main()</code>, so that it works just like <code>stdout</code>. </p>
  
  <p>I would guess that this is somewhat hard to do in a portable way, since the C standard wants prior-to-main initialized variables to be constants or string literals, and that <code>stdout</code> gets special compiler treatment. But I'm not sure, so I want to ask: </p>
  
  <p>Is it possible to write a C library such that stuff like <code>extern FILE* not_stdout</code> is initialized before the first line of <code>main()</code> whenever the library is included?</p>