Is it safe to use standard library functions before calling the main () function?

Consider the following code:

#include <iostream>

bool preInit()
{
    std::cerr << "Doing preinitialization...\n";
    return true;
}

const bool preinitialized=preInit();

int main()
{
    std::cerr << "In main()\nPreinitialization has "
              << (preinitialized ? "" : "not ") << "been done\n";
}

Is std::cerr(and any other means of the C ++ standard library) used in preInit()here? Is the library guaranteed to be ready for use before the call main()in accordance with the C ++ standard?

+4
source share

All Articles