[LLVMdev] Different behavoir when writing to stdout with 2 raw_fd_ostreams with or w/o redirection

Dmitry N. Mikushin maemarcus at gmail.com
Wed Nov 28 22:54:04 PST 2012


Dear all,

Consider there is a program that writes to stdout using two different
raw_fd_ostream-s:

#include "llvm/LLVMContext.h"
#include "llvm/Module.h"
#include "llvm/Support/raw_ostream.h"

using namespace llvm;

int main()
{
        raw_fd_ostream S(STDOUT_FILENO, false);

        outs() << "Hello";
        S << ", world!";

        return 0;
}

With this layout everything is fine, it prints ", world!Hello"

Now, make S definition global:

#include "llvm/LLVMContext.h"
#include "llvm/Module.h"
#include "llvm/Support/raw_ostream.h"

using namespace llvm;

raw_fd_ostream S(STDOUT_FILENO, false);

int main()
{
        outs() << "Hello";
        S << ", world!";

        return 0;
}

And... surprisingly:

$ ./outs
Hello, world!$ ./outs &>result
$ cat result
HelloLLVM ERROR: IO failure on output stream.

So, no error with screen output and error when redirected to file. Why so?

Thanks,
- D.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20121129/7c148904/attachment.html>


More information about the llvm-dev mailing list