I am working on a project which includes startup code prior to the call to main
. I am however unaware of the std library initializations.
I know that the following code will throw a segmentation fault.
#include <iostream>
void foo(void) __attribute__((constructor));
void foo() {
std::cout << "foo" << std::endl;
}
int main() {
std::cout << "Simple program to throw a segmentation fault" << std::endl;
}
The above code can be made to work by force initializing the ostream buffer (not sure if it's exactly ostream) by using std::ios_base::Init mInitializer;
. This would mean that the std library was not completely initialized at this point (that is my inference of the above example).
So when can I use std functions without actually breaking the code? Is there a way to force initialize complete std library?