writeln() assertion failed in hybrid x64
    Szymon Gatner via Digitalmars-d-learn 
    digitalmars-d-learn at puremagic.com
       
    Wed Sep  3 02:55:53 PDT 2014
    
    
  
Hey,
I am trying to build hybrid (C++, D) application (more here: 
http://forum.dlang.org/thread/ugkpqprobonorbdunxsx@forum.dlang.org) 
but I am now getting assertion failure from within writeln(). 
writeln() is called from a D function that has C++ linkage:
D definition:
extern (C++) void printSomething()
{
   writeln("hello from D");
}
usage from C++:
extern "C++" void printSomething();
int main()
{
   DRuntime druntime; // rt_init(), rt_term()
   printSomething();
}
this causes run-time assertion in fprintf() called from within 
writeln():
int __cdecl fprintf (
         FILE *str,
         const char *format,
         ...
         )
/*
  * 'F'ile (stream) 'PRINT', 'F'ormatted
  */
{
     va_list(arglist);
     FILE *stream;
     int buffing;
     int retval=0;
     _VALIDATE_RETURN( (str != NULL), EINVAL, -1); <=== assetion 
here
[...]
}
meaning that str arg passed is null. writelns()'s call site:
         enforce(fprintf(.stdout._p.handle, "%.*s\n",
                         cast(int) args[0].length, args[0].ptr) >= 
0);
so for some reason .stdout._p.handle is null.
    
    
More information about the Digitalmars-d-learn
mailing list