I have a C++11 program that uses std::fprintf
to write to stderr
as a log and debug info. I know fprintf
can fail and return a negative value, but I can't found if the operation is atomic (if fails, has no effect) or it can write some part of the text and then fails (or any other side effect).
The function that uses fprintf
looks like this:
void writeToConsole (std::string const &message)
{
std::fprintf(stderr, "%s\n", message.c_str());
}
I am developing using Clang and GCC on Linux (for now), but my question is more about the standard, so...
Question:
If std::printf
fails, is still possible that some characters had been wrote to stderr
? Is this behaviour a C/C++ standard or is implementation-defined?
Even more, if std::printf
fails, should I abort the program or can continue execution silently without side effects (other than impossibility of write to stderr
)?
Aucun commentaire:
Enregistrer un commentaire