digitalmars.D.learn - Question about calling D method from C/C++
- Eric (19/19) Jun 02 2013 If I use "new" inside a D method that is called from a c++ program
- Jacob Carlborg (6/25) Jun 02 2013 It seems you haven't started the runtime.
- Eric (3/8) Jun 03 2013 Thanks. That fixed my problem. This is my first D program,
- Jacob Carlborg (5/7) Jun 03 2013 If it's not obvious, you should terminate the runtime as well when your
- Eric (2/8) Jun 03 2013 Thanks. I would not have guessed that either...
If I use "new" inside a D method that is called from a c++ program it causes a segmentation fault. For example: C++ code: #include "dcode.h" int main(int argc, char *argv[]) { hello(); return(0); } D code: class X { private int x; this() { x = 5; } public int getX() { return(x); } } extern (C++) void hello() { X x = new X(); } This will crash when the line "X x = new X()" is executed. Is this to be expected?
Jun 02 2013
On 2013-06-03 06:32, Eric wrote:If I use "new" inside a D method that is called from a c++ program it causes a segmentation fault. For example: C++ code: #include "dcode.h" int main(int argc, char *argv[]) { hello(); return(0); } D code: class X { private int x; this() { x = 5; } public int getX() { return(x); } } extern (C++) void hello() { X x = new X(); } This will crash when the line "X x = new X()" is executed. Is this to be expected?It seems you haven't started the runtime. Use this function: https://github.com/D-Programming-Language/druntime/blob/master/src/rt/dmain2.d#L281 -- /Jacob Carlborg
Jun 02 2013
Thanks. That fixed my problem. This is my first D program, so I wouldn't have figured it out on my own... -EricThis will crash when the line "X x = new X()" is executed. Is this to be expected?It seems you haven't started the runtime. Use this function: https://github.com/D-Programming-Language/druntime/blob/master/src/rt/dmain2.d#L281
Jun 03 2013
On 2013-06-03 17:42, Eric wrote:Thanks. That fixed my problem. This is my first D program, so I wouldn't have figured it out on my own...If it's not obvious, you should terminate the runtime as well when your program ends. There's a corresponding function for that. -- /Jacob Carlborg
Jun 03 2013
On Monday, 3 June 2013 at 17:20:22 UTC, Jacob Carlborg wrote:On 2013-06-03 17:42, Eric wrote:Thanks. I would not have guessed that either...Thanks. That fixed my problem. This is my first D program, so I wouldn't have figured it out on my own...If it's not obvious, you should terminate the runtime as well when your program ends. There's a corresponding function for that.
Jun 03 2013