setmode again

Brian Myers bmyers at harryanddavid.com
Fri Aug 8 13:14:32 PDT 2008


Hi Walter,

The following code compiled with DMC still doesn't work:

#include <fcntl.h>
#include <io.h>
#include <string.h>
#include <stdio.h>

void main() {
    char *tmp = "Test line1\r\ntest line2\n";
    //_setmode(_fileno(stdout), _O_BINARY);
    stdout->_flag &= ~_IOTRAN;
    fwrite(tmp, strlen(tmp), sizeof(char), stdout);
}

Want me to try anything else?

Walter Bright Wrote:

> Brian Myers wrote:
> > No, I haven't because I thought that would result in a compiler or
> > linker error. What happens is the function is executed at run time,
> > but has no effect. I think I have a better idea now thought:
> > 
> > Check out this C code:
> > 
> > #include <fcntl.h> #include <io.h> #include <string.h> #include
> > <stdio.h>
> > 
> > void main() { char *tmp = "Test line1\r\ntest line2\n"; 
> > _setmode(_fileno(stdout), _O_BINARY); fwrite(tmp, strlen(tmp),
> > sizeof(char), stdout); }
> > 
> > When compiled and linked with MSVC, it works properly. When compiled
> > with DMC, it doesn't. Could there be something wrong with the DMC
> > CRT? I would suspect the D runtime library is built on the same code,
> > and that's why it's not working properly.
> 
> Try:
> 	stdout->_flag &= ~_IOTRAN;
> in the C code.




More information about the Digitalmars-d mailing list