digitalmars.D - Is it possible to call D functions from C++
- Namal (3/3) Mar 18 2015 Hello, as in the title. How can I call D functions from C++ (If
- Benjamin Thaut (16/19) Mar 18 2015 D:
- krzaq (3/23) Mar 18 2015 I'm pretty sure the OP wanted to call D functions from C++, not
- Benjamin Thaut (3/5) Mar 18 2015 If you look very closely you will notice that my example does
- krzaq (3/9) Mar 18 2015 Oh, right. I'm sorry, I assumed void main() means D, since it's
- Kagamin (2/4) Mar 19 2015 C++ allows implementation-defined return type of main.
- krzaq (3/10) Mar 19 2015 I'm afraid that you've mistaken C++ for C. The C++ standard quite
- Kagamin (2/3) Mar 19 2015 This.
- krzaq (4/7) Mar 19 2015 I'm not sure what you're failing to understand here. It **shall*
- Kagamin (2/2) Mar 19 2015 Hmm... I read it as "it shall have the return type of int, but if
- krzaq (2/4) Mar 19 2015 In that case, I refer you to https://www.ietf.org/rfc/rfc2119.txt
- Andre Kostur (4/8) Mar 20 2015 To be picky (because I live in RFCs)... RFC 2119 doesn't have anything
- Andrei Alexandrescu (2/4) Mar 19 2015 "shall" is prescriptive in standardese, i.e. means "must". -- Andrei
- "Ola Fosheim =?UTF-8?B?R3LDuHN0YWQi?= (3/5) Mar 20 2015 The semantics of returning from main() is defined as:
- Daniel Kozak (4/24) Mar 18 2015 he probably will need cal rt_init and rt_term too.
- Namal (18/18) Mar 18 2015 alright, thanks alot. Now I have.
- Kagamin (3/5) Mar 18 2015 Try C example first:
- Benjamin Thaut (3/5) Mar 18 2015 What platform are you on, windows, linux, osx? What c++ compiler
- Namal (3/9) Mar 19 2015 Linux, gcc and dmd. In my case c++ refuses to compile
- Benjamin Thaut (2/13) Mar 19 2015 well then change it to the full signature ;-)
- Chris (4/7) Mar 18 2015 http://dlang.org/cpp_interface.html
Hello, as in the title. How can I call D functions from C++ (If my main() is in a c++ file). Thanks alot!
Mar 18 2015
On Wednesday, 18 March 2015 at 14:17:13 UTC, Namal wrote:Hello, as in the title. How can I call D functions from C++ (If my main() is in a c++ file). Thanks alot!D: extern(C++) void SomeDFunction() { doSomething(); } C++: void SomeDFunction(); void main() { SomeDFunction(); } Please also see: http://dlang.org/cpp_interface.html Kind Regards Benjamin
Mar 18 2015
On Wednesday, 18 March 2015 at 14:20:19 UTC, Benjamin Thaut wrote:On Wednesday, 18 March 2015 at 14:17:13 UTC, Namal wrote:I'm pretty sure the OP wanted to call D functions from C++, not C++ functions from D.Hello, as in the title. How can I call D functions from C++ (If my main() is in a c++ file). Thanks alot!D: extern(C++) void SomeDFunction() { doSomething(); } C++: void SomeDFunction(); void main() { SomeDFunction(); } Please also see: http://dlang.org/cpp_interface.html Kind Regards Benjamin
Mar 18 2015
On Wednesday, 18 March 2015 at 14:40:48 UTC, krzaq wrote:I'm pretty sure the OP wanted to call D functions from C++, not C++ functions from D.If you look very closely you will notice that my example does exactly what the OP wanted.
Mar 18 2015
On Wednesday, 18 March 2015 at 15:51:28 UTC, Benjamin Thaut wrote:On Wednesday, 18 March 2015 at 14:40:48 UTC, krzaq wrote:Oh, right. I'm sorry, I assumed void main() means D, since it's not legit C++.I'm pretty sure the OP wanted to call D functions from C++, not C++ functions from D.If you look very closely you will notice that my example does exactly what the OP wanted.
Mar 18 2015
On Wednesday, 18 March 2015 at 15:54:04 UTC, krzaq wrote:Oh, right. I'm sorry, I assumed void main() means D, since it's not legit C++.C++ allows implementation-defined return type of main.
Mar 19 2015
On Thursday, 19 March 2015 at 07:42:48 UTC, Kagamin wrote:On Wednesday, 18 March 2015 at 15:54:04 UTC, krzaq wrote:I'm afraid that you've mistaken C++ for C. The C++ standard quite clearly says:Oh, right. I'm sorry, I assumed void main() means D, since it's not legit C++.C++ allows implementation-defined return type of main.An implementation shall not predefine the main function. This function shall not be overloaded. **It shall have a return type of type int**, but otherwise its type is implementation-defined.
Mar 19 2015
On Thursday, 19 March 2015 at 08:32:10 UTC, krzaq wrote:but otherwise its type is implementation-defined.This.
Mar 19 2015
On Thursday, 19 March 2015 at 08:33:07 UTC, Kagamin wrote:On Thursday, 19 March 2015 at 08:32:10 UTC, krzaq wrote:I'm not sure what you're failing to understand here. It **shall* have the return type of int. The rest (as in: parameter list) is implementation defined.but otherwise its type is implementation-defined.This.
Mar 19 2015
Hmm... I read it as "it shall have the return type of int, but if not, then it's implementation-defined".
Mar 19 2015
On Thursday, 19 March 2015 at 08:38:45 UTC, Kagamin wrote:Hmm... I read it as "it shall have the return type of int, but if not, then it's implementation-defined".In that case, I refer you to https://www.ietf.org/rfc/rfc2119.txt
Mar 19 2015
On 2015-03-19 1:57 AM, krzaq wrote:On Thursday, 19 March 2015 at 08:38:45 UTC, Kagamin wrote:To be picky (because I live in RFCs)... RFC 2119 doesn't have anything to say about "shall". It does have something to say about "SHALL". The capitalization is important.Hmm... I read it as "it shall have the return type of int, but if not, then it's implementation-defined".In that case, I refer you to https://www.ietf.org/rfc/rfc2119.txt
Mar 20 2015
On 3/19/15 1:38 AM, Kagamin wrote:Hmm... I read it as "it shall have the return type of int, but if not, then it's implementation-defined"."shall" is prescriptive in standardese, i.e. means "must". -- Andrei
Mar 19 2015
On Thursday, 19 March 2015 at 08:38:45 UTC, Kagamin wrote:Hmm... I read it as "it shall have the return type of int, but if not, then it's implementation-defined".The semantics of returning from main() is defined as: std::exit(main(…))
Mar 20 2015
On Wednesday, 18 March 2015 at 14:20:19 UTC, Benjamin Thaut wrote:On Wednesday, 18 March 2015 at 14:17:13 UTC, Namal wrote:he probably will need cal rt_init and rt_term too. similar post with example for C: http://forum.dlang.org/post/ljgtqa$1qb1$1 digitalmars.comHello, as in the title. How can I call D functions from C++ (If my main() is in a c++ file). Thanks alot!D: extern(C++) void SomeDFunction() { doSomething(); } C++: void SomeDFunction(); void main() { SomeDFunction(); } Please also see: http://dlang.org/cpp_interface.html Kind Regards Benjamin
Mar 18 2015
alright, thanks alot. Now I have. test.d import std.stdio; extern (C++) int foo(int i, int j, int k) { writefln("i = %s", i); writefln("j = %s", j); writefln("k = %s", k); return 1; } and main.cpp int foo(int i, int j, int k); int main() { foo(1,2,3); } Can you help me show how to compile and link it together please, thank you.
Mar 18 2015
On Wednesday, 18 March 2015 at 14:50:21 UTC, Namal wrote:Can you help me show how to compile and link it together please, thank you.Try C example first: http://forum.dlang.org/post/qppmeeakboxjzuuwreyy forum.dlang.org
Mar 18 2015
On Wednesday, 18 March 2015 at 14:50:21 UTC, Namal wrote:Can you help me show how to compile and link it together please, thank you.What platform are you on, windows, linux, osx? What c++ compiler do you use? msvc, clang, gcc?
Mar 18 2015
On Wednesday, 18 March 2015 at 15:52:33 UTC, Benjamin Thaut wrote:On Wednesday, 18 March 2015 at 14:50:21 UTC, Namal wrote:Linux, gcc and dmd. In my case c++ refuses to compile if main is void.Can you help me show how to compile and link it together please, thank you.What platform are you on, windows, linux, osx? What c++ compiler do you use? msvc, clang, gcc?
Mar 19 2015
On Thursday, 19 March 2015 at 11:47:37 UTC, Namal wrote:On Wednesday, 18 March 2015 at 15:52:33 UTC, Benjamin Thaut wrote:well then change it to the full signature ;-)On Wednesday, 18 March 2015 at 14:50:21 UTC, Namal wrote:Linux, gcc and dmd. In my case c++ refuses to compile if main is void.Can you help me show how to compile and link it together please, thank you.What platform are you on, windows, linux, osx? What c++ compiler do you use? msvc, clang, gcc?
Mar 19 2015
On Wednesday, 18 March 2015 at 14:17:13 UTC, Namal wrote:Hello, as in the title. How can I call D functions from C++ (If my main() is in a c++ file). Thanks alot!http://dlang.org/cpp_interface.html http://dlang.org/interfaceToC.html There is also D.learn ;)
Mar 18 2015