[LLVMdev] Binary output to cout on Windows
Michael Smith
Michael.Smith at synopsys.com
Tue May 23 10:27:09 PDT 2006
The solution (provided in Microsoft's documentation) is to add:
#include <cstdio>
#include <io.h>
#include <fcntl.h>
and run:
int result = _setmode( _fileno(stdin), _O_BINARY );
if( result == -1 )
{ std::cerr<<"Cannot set input mode to binary."<<std::endl; return 1;
}
result = _setmode( _fileno(stdout), _O_BINARY );
if( result == -1 )
{ std::cerr<<"Cannot set output mode to binary."<<std::endl; return 1;
}
before using cin or cout. I'm not sure where to add this however, since
it needs to be called before any reads or writes are done, but only
needs to be called once. Any suggestions? At the moment in my own code,
I'm adding them to the tools source files, since that's where it's
determined that cin/cout can be used for input/output.
~Michael
-----Original Message-----
From: llvmdev-bounces at cs.uiuc.edu [mailto:llvmdev-bounces at cs.uiuc.edu]
On Behalf Of Chris Lattner
Sent: Monday, May 22, 2006 4:36 PM
To: LLVM Developers Mailing List
Subject: RE: [LLVMdev] Binary output to cout on Windows
On Mon, 22 May 2006, Michael Smith wrote:
> llvm-as interprets "-" as using standard output (cout), so llvm-as <
> input.ll -o - | opt has the same behavior. You'll actually find a
> comment on it in llvm-as.cpp, so I guess I shouldn't hold out hope
that
> there's a good way to do it.
Please see:
http://www.parashift.com/c++-faq-lite/input-output.html#faq-15.13
We'd welcome patches to do this, and we can localize this in our system
support library, but you'd have to figure out the magic to make this
happen on win32.
-Chris
More information about the llvm-dev
mailing list