Re: Interfacing with C++ std::shared_ptr and std::unique_ptr

2020-06-10 Thread Andre Pany via Digitalmars-d-learn
On Wednesday, 10 June 2020 at 08:31:47 UTC, Mathias LANG wrote: On Wednesday, 10 June 2020 at 06:43:24 UTC, Andre Pany wrote: [...] Depending on your needs, it might be trivial. We use this, and it works accross all 3 platforms:

Re: Interfacing with C++ std::shared_ptr and std::unique_ptr

2020-06-10 Thread Mathias LANG via Digitalmars-d-learn
On Wednesday, 10 June 2020 at 06:43:24 UTC, Andre Pany wrote: Hi, I would like to interface with the library https://github.com/NTNU-IHB/FMI4cpp and have following class definitions in the header file: ``` c++ namespace fmi4cpp { template class fmu_base { public: const

Re: Interfacing with C++ std::shared_ptr and std::unique_ptr

2020-06-10 Thread evilrat via Digitalmars-d-learn
On Wednesday, 10 June 2020 at 06:43:24 UTC, Andre Pany wrote: Also, the C++ classes make use of templates. Is it still possible to call these classes from D? It should be, I did something similar and it worked. But it was quite some time ago so I don't remember exact situation and any

Re: Interfacing to C++: Cannot access value from namespace

2019-09-07 Thread Andrew Edwards via Digitalmars-d-learn
On Saturday, 7 September 2019 at 12:39:25 UTC, Ali Çehreli wrote: On 09/07/2019 03:26 AM, Andrew Edwards wrote: > [1] I did not declare any of the other member variables from the struct, > don't know if this is a source of the problem. Yes, it definitely is a problem. The members are accessed

Re: Interfacing to C++: Cannot access value from namespace

2019-09-07 Thread Ali Çehreli via Digitalmars-d-learn
On 09/07/2019 03:26 AM, Andrew Edwards wrote: > [1] I did not declare any of the other member variables from the struct, > don't know if this is a source of the problem. Yes, it definitely is a problem. The members are accessed as byte offsets into their objects. Without defining the other

Re: Interfacing to C++: Cannot access value from namespace

2019-09-07 Thread Andrew Edwards via Digitalmars-d-learn
On Saturday, 7 September 2019 at 12:30:53 UTC, Andrew Edwards wrote: On Saturday, 7 September 2019 at 12:24:49 UTC, Ali Çehreli wrote: On 09/07/2019 03:26 AM, Andrew Edwards wrote: > float continuallyUpdatedValue; > float continuallyChangingValue; // [1] They mean the same thing for

Re: Interfacing to C++: Cannot access value from namespace

2019-09-07 Thread Andrew Edwards via Digitalmars-d-learn
On Saturday, 7 September 2019 at 12:24:49 UTC, Ali Çehreli wrote: On 09/07/2019 03:26 AM, Andrew Edwards wrote: > float continuallyUpdatedValue; > float continuallyChangingValue; // [1] They mean the same thing for an English speaker but compilers don't know that (yet?). :) Ali

Re: Interfacing to C++: Cannot access value from namespace

2019-09-07 Thread Ali Çehreli via Digitalmars-d-learn
On 09/07/2019 03:26 AM, Andrew Edwards wrote: > float continuallyUpdatedValue; > float continuallyChangingValue; // [1] They mean the same thing for an English speaker but compilers don't know that (yet?). :) Ali

Re: Interfacing with C libs: weeding through C/C++ macros and such in header files

2019-01-13 Thread Mike Parker via Digitalmars-d-learn
On Sunday, 13 January 2019 at 22:40:57 UTC, Alec Stewart wrote: Example without code; for some reason a macro is defined for the stdlib functions `malloc`, `realloc`, and `free`. Maybe it's just because I don't have any pro experience with C or C++, but that seems a bit excessive. Or I

Re: Interfacing with C libs: weeding through C/C++ macros and such in header files

2019-01-13 Thread Alec Stewart via Digitalmars-d-learn
On Sunday, 13 January 2019 at 23:23:50 UTC, Alex wrote: These three are members of the standard library in D. https://dlang.org/phobos/core_memory.html Ah, yea that's way easier. At first, I would suggest to try out some automatic converters, which are written by the community:

Re: Interfacing with C libs: weeding through C/C++ macros and such in header files

2019-01-13 Thread Alex via Digitalmars-d-learn
On Sunday, 13 January 2019 at 22:40:57 UTC, Alec Stewart wrote: Example without code; for some reason a macro is defined for the stdlib functions `malloc`, `realloc`, and `free`. Maybe it's just because I don't have any pro experience with C or C++, but that seems a bit excessive. Or I could

Re: Interfacing with C++ Class named Object

2018-05-01 Thread Robert M. Münch via Digitalmars-d-learn
On 2018-05-01 17:14:53 +, Robert M. Münch said: Yes, great! Thanks. I could extend the code now. But I get a next problem: extern (C++, b2d) { class AnyBase { bool isShared(); } pragma(mangle, "Object"); class b2dObject : AnyBase { } class Image : b2dObject { // class

Re: Interfacing with C++ Class named Object

2018-05-01 Thread Robert M. Münch via Digitalmars-d-learn
On 2018-05-01 16:07:30 +, Timoses said: On Tuesday, 1 May 2018 at 15:24:09 UTC, Robert M. Münch wrote: Hi, I'm mostly doing simple C-API wrappers around C++ code to access thigns from D. However, I wanted to try how far I can come using C++ directly. I have the following C++ code in

Re: Interfacing with C++ Class named Object

2018-05-01 Thread Timoses via Digitalmars-d-learn
On Tuesday, 1 May 2018 at 15:24:09 UTC, Robert M. Münch wrote: Hi, I'm mostly doing simple C-API wrappers around C++ code to access thigns from D. However, I wanted to try how far I can come using C++ directly. I have the following C++ code in namespace N: class Image : public Object {

Re: Interfacing with C++

2018-02-05 Thread Timothee Cour via Digitalmars-d-learn
https://github.com/opencv/opencv/issues/6585#issuecomment-221842441 snip: > "C-API" is not supported and should be removed totally (but we have a lack of > resources to port this legacy C code to C++, so some of this code still > exists right now). Also huge part of fresh OpenCV functionality

Re: Interfacing with C++

2018-02-05 Thread Kagamin via Digitalmars-d-learn
On Sunday, 4 February 2018 at 08:33:20 UTC, Mike Parker wrote: Though, I'm curious why anyone would want to declare a callback in a C++ program as cdecl only on Windows and use the default C++ convention everywhere else. I suggest you dig into it and make sure that's what's intended. And good

Re: Interfacing with C++

2018-02-04 Thread Timothee Cour via Digitalmars-d-learn
Calypso (https://github.com/Syniurge/Calypso/) is the most promising way to interface with C++, it requires 0 bindings and understands all of C++ (templates etc); there are some caveats/kinks that are being ironed out (and any help is welcome). On Sun, Feb 4, 2018 at 4:37 AM, rjframe via

Re: Interfacing with C++

2018-02-04 Thread rjframe via Digitalmars-d-learn
On Sun, 04 Feb 2018 08:33:20 +, Mike Parker wrote: > Though, I'm curious why anyone would want to declare a callback in a C++ > program as cdecl only on Windows and use the default C++ > convention everywhere else. I suggest you dig into it and make sure > that's what's intended. And good

Re: Interfacing with C++

2018-02-04 Thread Seb via Digitalmars-d-learn
On Sunday, 4 February 2018 at 10:42:22 UTC, infinityplusb wrote: On Sunday, 4 February 2018 at 08:33:20 UTC, Mike Parker wrote: [...] it is, everyone keeps saying writing bindings in D is super easy ... I feel this is a slight simplification. :( [...] Sounds easy enough. [...] [...]

Re: Interfacing with C++

2018-02-04 Thread infinityplusb via Digitalmars-d-learn
On Sunday, 4 February 2018 at 08:33:20 UTC, Mike Parker wrote: On Sunday, 4 February 2018 at 08:17:31 UTC, Mike Parker wrote: Assuming this is OpenCV ... it is, everyone keeps saying writing bindings in D is super easy ... I feel this is a slight simplification. :( version(Windows)

Re: Interfacing with C++

2018-02-04 Thread Mike Parker via Digitalmars-d-learn
On Sunday, 4 February 2018 at 08:17:31 UTC, Mike Parker wrote: So assuming CV_CDECL is cdecl, this should do it: extern(C) alias CvCmpFunc = int function(const(void)*, const(void)*, void*); Assuming this is OpenCV, Looking at [1], it's cdecl only on Windows. Empty everywhere else. So

Re: Interfacing with C++

2018-02-04 Thread Mike Parker via Digitalmars-d-learn
On Sunday, 4 February 2018 at 07:54:12 UTC, infinityplusb wrote: Hi all I'm looking to try and write an interface to C++, but given I'm a casual dabbler in D, it's slightly beyond my current ability in terms of both C++ and D! As a leg up, how would one translate something like this from

Re: Interfacing with C++

2018-02-04 Thread rikki cattermole via Digitalmars-d-learn
On 04/02/2018 7:54 AM, infinityplusb wrote: Hi all I'm looking to try and write an interface to C++, but given I'm a casual dabbler in D, it's slightly beyond my current ability in terms of both C++ and D! As a leg up, how would one translate something like this from C++ to D? `typedef int

Re: Interfacing with C - calling member function of D struct from C?

2017-06-25 Thread unleashy via Digitalmars-d-learn
On Sunday, 25 June 2017 at 02:09:53 UTC, Adam D. Ruppe wrote: On Sunday, 25 June 2017 at 02:05:35 UTC, unleashy wrote: How would I call `addToBar` from C code? You don't. Instead write it like: struct Foo { int bar; } extern(C) void addToBar(Foo* foo, int what) { foo.bar += what;

Re: Interfacing with C - calling member function of D struct from C?

2017-06-24 Thread Adam D. Ruppe via Digitalmars-d-learn
On Sunday, 25 June 2017 at 02:05:35 UTC, unleashy wrote: How would I call `addToBar` from C code? You don't. Instead write it like: struct Foo { int bar; } extern(C) void addToBar(Foo* foo, int what) { foo.bar += what; } Then define it in C the same way and you call it the

Re: interfacing with C: strings and byte vectors

2016-06-11 Thread ag0aep6g via Digitalmars-d-learn
On 06/11/2016 01:59 PM, yawniek wrote: i forgot to add a few important points: - the strings in vec_t are not c strings - vec_t might contain other data than strings the original ctor i pasted actually doesn't even work, temporarly i solved it like this(string s) { char[] si =

Re: interfacing with C: strings and byte vectors

2016-06-11 Thread yawniek via Digitalmars-d-learn
On Saturday, 11 June 2016 at 10:26:17 UTC, Mike Parker wrote: On Saturday, 11 June 2016 at 09:32:54 UTC, yawniek wrote: thanks mike for the in depth answer. i forgot to add a few important points: - the strings in vec_t are not c strings - vec_t might contain other data than strings the

Re: interfacing with C: strings and byte vectors

2016-06-11 Thread Mike Parker via Digitalmars-d-learn
On Saturday, 11 June 2016 at 09:32:54 UTC, yawniek wrote: so far i defined vec_t as: struct vec_t { char *base; size_t len; this(string s) { base = s.ptr; len = s.lenght; } nothrow @nogc inout(char)[] toString() inout @property { return base[0 .. len]; } nothrow @nogc

Re: Interfacing with C++

2014-11-02 Thread Kagamin via Digitalmars-d-learn
D.learn is about basics of D. Interfacing with C++ is an advanced topic, with feature set in flux, so I'd suggest to ask about it in http://forum.dlang.org/group/digitalmars.D group.

Re: Interfacing with C++

2014-11-01 Thread Kagamin via Digitalmars-d-learn
You can see http://wiki.dlang.org/DIP61 and linked discussions. Static and virtual functions probably work. Constructors and destructors probably don't. What's difficult is multiple inheritance. The information on C++ support is largely considered private to the compiler team.

Re: Interfacing to C

2011-06-28 Thread Jimmy Cao
On Tue, Jun 28, 2011 at 11:15 PM, Joshua Niehus jm.nie...@gmail.com wrote: Hello, I was trying to run the example on the Interfacing to C page ( http://www.d-programming-language.org/interfaceToC.html) and ran into few issues. To get it to work as is i was .dup(ing) strings into new chars

Re: Interfacing to C. extern (C) variables

2011-06-26 Thread Robert Clipsham
On 26/06/2011 20:54, Alex_Dovhal wrote: I'd like to call C functions and use C variables in D module. D calls C functions just fine, but how can I use C variables? extern(C) extern int myCVar; -- Robert http://octarineparrot.com/

Re: Interfacing to C. extern (C) variables

2011-06-26 Thread Jimmy Cao
On Sun, Jun 26, 2011 at 5:00 PM, Alex_Dovhal alex_dov...@yahoo.com wrote: Robert Clipsham rob...@octarineparrot.com wrote: On 26/06/2011 20:54, Alex_Dovhal wrote: I'd like to call C functions and use C variables in D module. D calls C functions just fine, but how can I use C variables?

Re: Interfacing to C. extern (C) variables

2011-06-26 Thread Alex_Dovhal
Jimmy Cao jcao...@gmail.com wrote: It works for me like this: extern(C){ __gshared int c_var; int func(); } Thanks.

Re: Interfacing with c and platform dependent sizes

2011-02-27 Thread Jacob Carlborg
On 2011-02-26 17:06, Mike Wey wrote: On 02/26/2011 11:49 AM, Jacob Carlborg wrote: On 2011-02-26 01:28, simendsjo wrote: C is not my strong side, so I'm having some problems wrapping some code. I found a couple of sources on this: 1) http://www.digitalmars.com/d/2.0/htomodule.html 2)

Re: Interfacing with c and platform dependent sizes

2011-02-27 Thread Jacob Carlborg
On 2011-02-26 17:58, simendsjo wrote: On 26.02.2011 17:06, Mike Wey wrote: On 02/26/2011 11:49 AM, Jacob Carlborg wrote: On 2011-02-26 01:28, simendsjo wrote: C is not my strong side, so I'm having some problems wrapping some code. I found a couple of sources on this: 1)

Re: Interfacing with c and platform dependent sizes

2011-02-27 Thread Steven Schveighoffer
On Sat, 26 Feb 2011 22:24:52 -0500, Bekenn leav...@alone.com wrote: On 2/25/2011 7:24 PM, Steven Schveighoffer wrote: BTW, I think long long is a gnu extension, it's not standard C (I don't think long long exists in Visual C for instance). I'm pretty sure it's standard as of C99 (though not

Re: Interfacing with c and platform dependent sizes

2011-02-27 Thread simendsjo
On 27.02.2011 11:43, Jacob Carlborg wrote: On 2011-02-26 17:58, simendsjo wrote: On 26.02.2011 17:06, Mike Wey wrote: On 02/26/2011 11:49 AM, Jacob Carlborg wrote: On 2011-02-26 01:28, simendsjo wrote: C is not my strong side, so I'm having some problems wrapping some code. I found a couple

Re: Interfacing with c and platform dependent sizes

2011-02-27 Thread Jonathan M Davis
On Sunday 27 February 2011 05:41:49 Steven Schveighoffer wrote: On Sat, 26 Feb 2011 22:24:52 -0500, Bekenn leav...@alone.com wrote: On 2/25/2011 7:24 PM, Steven Schveighoffer wrote: BTW, I think long long is a gnu extension, it's not standard C (I don't think long long exists in Visual C

Re: Interfacing with c and platform dependent sizes

2011-02-26 Thread Jacob Carlborg
On 2011-02-26 01:28, simendsjo wrote: C is not my strong side, so I'm having some problems wrapping some code. I found a couple of sources on this: 1) http://www.digitalmars.com/d/2.0/htomodule.html 2) http://www.digitalmars.com/d/2.0/interfaceToC.html 1) C's long is the same as D's int. long

Re: Interfacing with c and platform dependent sizes

2011-02-26 Thread Jacob Carlborg
On 2011-02-26 02:35, Jonathan M Davis wrote: On Friday, February 25, 2011 17:16:31 simendsjo wrote: On 26.02.2011 02:06, bearophile wrote: simendsjo: So.. A long in C is the same as the platform size? And long long doesn't exist in 64 bit? In D the size of int/uint is 32 bits and long/ulong

Re: Interfacing with c and platform dependent sizes

2011-02-26 Thread Mike Wey
On 02/26/2011 11:49 AM, Jacob Carlborg wrote: On 2011-02-26 01:28, simendsjo wrote: C is not my strong side, so I'm having some problems wrapping some code. I found a couple of sources on this: 1) http://www.digitalmars.com/d/2.0/htomodule.html 2)

Re: Interfacing with c and platform dependent sizes

2011-02-26 Thread simendsjo
On 26.02.2011 17:06, Mike Wey wrote: On 02/26/2011 11:49 AM, Jacob Carlborg wrote: On 2011-02-26 01:28, simendsjo wrote: C is not my strong side, so I'm having some problems wrapping some code. I found a couple of sources on this: 1) http://www.digitalmars.com/d/2.0/htomodule.html 2)

Re: Interfacing with c and platform dependent sizes

2011-02-26 Thread Mike Wey
On 02/26/2011 05:58 PM, simendsjo wrote: On 26.02.2011 17:06, Mike Wey wrote: On 02/26/2011 11:49 AM, Jacob Carlborg wrote: On 2011-02-26 01:28, simendsjo wrote: C is not my strong side, so I'm having some problems wrapping some code. I found a couple of sources on this: 1)

Re: Interfacing with c and platform dependent sizes

2011-02-26 Thread Bekenn
On 2/25/2011 7:24 PM, Steven Schveighoffer wrote: BTW, I think long long is a gnu extension, it's not standard C (I don't think long long exists in Visual C for instance). I'm pretty sure it's standard as of C99 (though not yet for C++; that's coming with C++0x). MSVC does indeed support it.

Re: Interfacing with c and platform dependent sizes

2011-02-25 Thread bearophile
simendsjo: So.. A long in C is the same as the platform size? And long long doesn't exist in 64 bit? In D the size of int/uint is 32 bits and long/ulong is 64 bits. In C the size of int, unsigned int, long, long long int, unsigned long long int, etc are not fixed, the change according to

Re: Interfacing with c and platform dependent sizes

2011-02-25 Thread simendsjo
On 26.02.2011 02:06, bearophile wrote: simendsjo: So.. A long in C is the same as the platform size? And long long doesn't exist in 64 bit? In D the size of int/uint is 32 bits and long/ulong is 64 bits. In C the size of int, unsigned int, long, long long int, unsigned long long int, etc

Re: Interfacing with c and platform dependent sizes

2011-02-25 Thread Steven Schveighoffer
On Fri, 25 Feb 2011 20:06:04 -0500, bearophile bearophileh...@lycos.com wrote: simendsjo: So.. A long in C is the same as the platform size? And long long doesn't exist in 64 bit? In D the size of int/uint is 32 bits and long/ulong is 64 bits. In C the size of int, unsigned int, long,

Re: Interfacing with c and platform dependent sizes

2011-02-25 Thread Jonathan M Davis
On Friday, February 25, 2011 17:35:02 Jonathan M Davis wrote: On Friday, February 25, 2011 17:16:31 simendsjo wrote: On 26.02.2011 02:06, bearophile wrote: simendsjo: So.. A long in C is the same as the platform size? And long long doesn't exist in 64 bit? In D the size of