www.digitalmars.com         C & C++   DMDScript  

c++ - fdopen bug

Here is a small C program who does not work
when compiled with Digital Mars C/C++ Compiler Version 8.49.4n

It does run Ok with
  VC 6.0
  gcc (MingW and Cygwin)

I think it should work with DMC.

--- result execution ---
fileno(stdin):  0040A180 0
fileno(stdout): 0040A1A0 1
fileno(stderr): 0040A1C0 2
Assertion failure: 'fp' on line 17 in file '0.c'

abnormal program termination

--- program ---
#include <stdio.h>
#include <io.h>
#include <fcntl.h>
#include <assert.h>
#include <stdlib.h>
#ifdef __CYGWIN__
#include <unistd.h>
int main( )
  FILE *fp;
  int fd;
  fprintf( stderr, "fileno(stdin):  %p %d\n", stdin, fileno(stdin) );
  fprintf( stderr, "fileno(stdout): %p %d\n", stdout, fileno(stdout) );
  fprintf( stderr, "fileno(stderr): %p %d\n", stderr, fileno(stderr) );
  fd = fileno(stdout); assert(fd!=-1);
  fp = fdopen(fd,"w"); assert(fp);
  fprintf(fp, "Ok.\n");
  return 0;
Sep 16 2006