Re: Using a struct as a wrapper for an extern(C) opaque type, no default constructor, what do?

2015-12-16 Thread Jakob Ovrum via Digitalmars-d-learn
On Thursday, 17 December 2015 at 06:04:14 UTC, Jeremy DeHaan wrote: And I guess what I was talking about before is that using a factory method feels klunky to me. If the things I am wrapping had been written in D they could use default initialization, so it feels wrong to do otherwise. I also j

Re: Using a struct as a wrapper for an extern(C) opaque type, no default constructor, what do?

2015-12-16 Thread Jeremy DeHaan via Digitalmars-d-learn
On Thursday, 17 December 2015 at 04:59:20 UTC, Jakob Ovrum wrote: On Thursday, 17 December 2015 at 04:05:30 UTC, Jeremy DeHaan wrote: http://dpaste.com/3FH3W13 Also, I would be wary of lazy initialization. We have bad experiences with it for AAs and standard containers. A typical example wou

Re: Using a struct as a wrapper for an extern(C) opaque type, no default constructor, what do?

2015-12-16 Thread Jakob Ovrum via Digitalmars-d-learn
On Thursday, 17 December 2015 at 04:05:30 UTC, Jeremy DeHaan wrote: Thanks. I guess what bugs me is that I always try to hide the fact that the API is a wrapper around C stuff, ie, I want to make people feel as though they're using idiomatic D. Doing something like this makes it feel like less

Re: Using a struct as a wrapper for an extern(C) opaque type, no default constructor, what do?

2015-12-16 Thread Jakob Ovrum via Digitalmars-d-learn
On Thursday, 17 December 2015 at 04:05:30 UTC, Jeremy DeHaan wrote: http://dpaste.com/3FH3W13 Also, I would be wary of lazy initialization. We have bad experiences with it for AAs and standard containers. A typical example would be: void foo(Wrapper w) { ... w.doTheThing(); ...

Re: Using a struct as a wrapper for an extern(C) opaque type, no default constructor, what do?

2015-12-16 Thread Jeremy DeHaan via Digitalmars-d-learn
On Thursday, 17 December 2015 at 03:43:58 UTC, Jakob Ovrum wrote: On Thursday, 17 December 2015 at 03:31:37 UTC, Jeremy DeHaan wrote: Hi all. I'm interfacing to some C code which include an opaque type and some C functions that create and work with a pointer to that type. I want to wrap up ever

Re: Using a struct as a wrapper for an extern(C) opaque type, no default constructor, what do?

2015-12-16 Thread Jakob Ovrum via Digitalmars-d-learn
On Thursday, 17 December 2015 at 03:31:37 UTC, Jeremy DeHaan wrote: Hi all. I'm interfacing to some C code which include an opaque type and some C functions that create and work with a pointer to that type. I want to wrap up everything in a struct, and the only thing that seems to bug me is ini

Using a struct as a wrapper for an extern(C) opaque type, no default constructor, what do?

2015-12-16 Thread Jeremy DeHaan via Digitalmars-d-learn
Hi all. I'm interfacing to some C code which include an opaque type and some C functions that create and work with a pointer to that type. I want to wrap up everything in a struct, and the only thing that seems to bug me is initialization. Since it is C code, I obviously can't read the functio

Re: extern(C) with function returning user type

2015-08-01 Thread Kyoji Klyden via Digitalmars-d-learn
On Saturday, 1 August 2015 at 04:11:02 UTC, Laeeth Isharc wrote: Walter observes that if you are a Java programmer and start writing D, you will write D like you write Java. And so I suppose one will see what one doesn't have in Java, but not so much the benefits of D. That's true of other la

Re: extern(C) with function returning user type

2015-07-31 Thread Laeeth Isharc via Digitalmars-d-learn
On Friday, 31 July 2015 at 21:35:30 UTC, Kyoji Klyden wrote: On Friday, 31 July 2015 at 19:13:18 UTC, Laeeth Isharc wrote: On Friday, 31 July 2015 at 17:14:29 UTC, Kyoji Klyden wrote: On Friday, 31 July 2015 at 16:09:23 UTC, bachmeier wrote: On Friday, 31 July 2015 at 03:30:20 UTC, Kyoji Klyde

Re: extern(C) with function returning user type

2015-07-31 Thread Kyoji Klyden via Digitalmars-d-learn
On Friday, 31 July 2015 at 19:13:18 UTC, Laeeth Isharc wrote: On Friday, 31 July 2015 at 17:14:29 UTC, Kyoji Klyden wrote: On Friday, 31 July 2015 at 16:09:23 UTC, bachmeier wrote: On Friday, 31 July 2015 at 03:30:20 UTC, Kyoji Klyden wrote: So idk, it feels silly and counterproductive to have

Re: extern(C) with function returning user type

2015-07-31 Thread Laeeth Isharc via Digitalmars-d-learn
On Friday, 31 July 2015 at 17:14:29 UTC, Kyoji Klyden wrote: On Friday, 31 July 2015 at 16:09:23 UTC, bachmeier wrote: On Friday, 31 July 2015 at 03:30:20 UTC, Kyoji Klyden wrote: So idk, it feels silly and counterproductive to have D not able to natively use C libraries. Are we just gonna have

Re: extern(C) with function returning user type

2015-07-31 Thread Kyoji Klyden via Digitalmars-d-learn
On Friday, 31 July 2015 at 16:09:23 UTC, bachmeier wrote: On Friday, 31 July 2015 at 03:30:20 UTC, Kyoji Klyden wrote: So idk, it feels silly and counterproductive to have D not able to natively use C libraries. Are we just gonna have to write D bindings to every notable library out there? Also

Re: extern(C) with function returning user type

2015-07-31 Thread bachmeier via Digitalmars-d-learn
On Friday, 31 July 2015 at 03:30:20 UTC, Kyoji Klyden wrote: So idk, it feels silly and counterproductive to have D not able to natively use C libraries. Are we just gonna have to write D bindings to every notable library out there? Also I don't see how it'd be problematic, if you don't want a

Re: extern(C) with function returning user type

2015-07-30 Thread Kyoji Klyden via Digitalmars-d-learn
On Thursday, 30 July 2015 at 11:32:10 UTC, bachmeier wrote: On Thursday, 30 July 2015 at 01:14:06 UTC, Mike Parker wrote: On Wednesday, 29 July 2015 at 18:42:45 UTC, Kyoji Klyden wrote: Thanks for the replies, This issue really highlights one of D's weak points I think. I've atleast got a rou

Re: extern(C) with function returning user type

2015-07-30 Thread Jacob Carlborg via Digitalmars-d-learn
On 2015-07-29 20:42, Kyoji Klyden wrote: Thanks for the replies, This issue really highlights one of D's weak points I think. I've atleast got a round about solution almost working. :P You might want to check out Calypso [1] as well. [1] http://forum.dlang.org/thread/nsjafpymezlqdknmn...@fo

Re: extern(C) with function returning user type

2015-07-30 Thread bachmeier via Digitalmars-d-learn
On Thursday, 30 July 2015 at 01:14:06 UTC, Mike Parker wrote: On Wednesday, 29 July 2015 at 18:42:45 UTC, Kyoji Klyden wrote: Thanks for the replies, This issue really highlights one of D's weak points I think. I've atleast got a round about solution almost working. :P Really? I see it as on

Re: extern(C) with function returning user type

2015-07-29 Thread Mike Parker via Digitalmars-d-learn
On Wednesday, 29 July 2015 at 18:42:45 UTC, Kyoji Klyden wrote: Thanks for the replies, This issue really highlights one of D's weak points I think. I've atleast got a round about solution almost working. :P Really? I see it as one of D's strengths. It's much easier to connect D with C than

Re: extern(C) with function returning user type

2015-07-29 Thread Kyoji Klyden via Digitalmars-d-learn
Thanks for the replies, This issue really highlights one of D's weak points I think. I've atleast got a round about solution almost working. :P

Re: extern(C) with function returning user type

2015-07-29 Thread anonymous via Digitalmars-d-learn
On Wednesday, 29 July 2015 at 17:59:26 UTC, Kyoji Klyden wrote: How would I use a C function that's returning a struct? auto doesn't work here, and from what I can tell D can't import C headers. (If it really can't then, that would be a very welcome feature) I do have the required libs but I

Re: extern(C) with function returning user type

2015-07-29 Thread Ali Çehreli via Digitalmars-d-learn
On 07/29/2015 10:59 AM, Kyoji Klyden wrote: > How would I use a C function that's returning a struct? The binding file must have a matching D struct. > auto doesn't > work here, and from what I can tell D can't import C headers. (If it > really can't then, that would be a very welcome feature)

Re: extern(C) with function returning user type

2015-07-29 Thread yawniek via Digitalmars-d-learn
On Wednesday, 29 July 2015 at 17:59:26 UTC, Kyoji Klyden wrote: How would I use a C function that's returning a struct? auto doesn't work here, and from what I can tell D can't import C headers. (If it really can't then, that would be a very welcome feature) I do have the required libs but I

extern(C) with function returning user type

2015-07-29 Thread Kyoji Klyden via Digitalmars-d-learn
How would I use a C function that's returning a struct? auto doesn't work here, and from what I can tell D can't import C headers. (If it really can't then, that would be a very welcome feature) I do have the required libs but I can't create my D obj file so I can't really get there. I know

Re: why adding extern(C) cause a runtime error?

2015-07-11 Thread Dav1d via Digitalmars-d-learn
On Saturday, 11 July 2015 at 01:22:14 UTC, mzf wrote: win7 x86 dmd2.067.1 ok ubuntu x64 dmd2.067.1 error - import std.stdio; import std.socket; extern(C) void recv() { writeln("recv..."); } extern(C) void send() { writeln("sen

why adding extern(C) cause a runtime error?

2015-07-10 Thread mzfhhhh via Digitalmars-d-learn
win7 x86 dmd2.067.1 ok ubuntu x64 dmd2.067.1 error - import std.stdio; import std.socket; extern(C) void recv() { writeln("recv..."); } extern(C) void send() { writeln("send..."); } int main(string[] argv) { //copy from

Re: Fixed Length Array Syntax in extern(C) Function Signatures

2015-07-10 Thread via Digitalmars-d-learn
On Friday, 10 July 2015 at 08:54:57 UTC, Andrea Fontana wrote: Is there any tool out there that automatically creates D wrappers from C headers`? https://github.com/jacob-carlborg/dstep ? Great! I'll try that!

Re: Fixed Length Array Syntax in extern(C) Function Signatures

2015-07-10 Thread Andrea Fontana via Digitalmars-d-learn
On Friday, 10 July 2015 at 08:42:06 UTC, Per Nordlöw wrote: On Friday, 10 July 2015 at 03:18:23 UTC, Mike Parker wrote: [1]http://dlang.org/interfaceToC.html Is there any tool out there that automatically creates D wrappers from C headers`? https://github.com/jacob-carlborg/dstep ?

Re: Fixed Length Array Syntax in extern(C) Function Signatures

2015-07-10 Thread via Digitalmars-d-learn
On Friday, 10 July 2015 at 03:18:23 UTC, Mike Parker wrote: [1]http://dlang.org/interfaceToC.html Is there any tool out there that automatically creates D wrappers from C headers`?

Re: Fixed Length Array Syntax in extern(C) Function Signatures

2015-07-10 Thread Nordlöw
On Friday, 10 July 2015 at 03:18:23 UTC, Mike Parker wrote: You should just be able to replace `[4]` with `*` in the arguments. [1]http://dlang.org/interfaceToC.html Great! One more thing: How shall my call to `avg_image_copy()` (from D) look then? Is the slicing syntax `[0 .. 4]` I use abo

Re: Fixed Length Array Syntax in extern(C) Function Signatures

2015-07-09 Thread Mike Parker via Digitalmars-d-learn
On Thursday, 9 July 2015 at 17:42:33 UTC, Alex Parrill wrote: On Thursday, 9 July 2015 at 17:11:36 UTC, Per Nordlöw wrote: On Thursday, 9 July 2015 at 16:12:27 UTC, Timon Gehr wrote: No. You'll need explicit pass by reference on the D side. So, how should I modify my call to `image_copy` with

Re: Fixed Length Array Syntax in extern(C) Function Signatures

2015-07-09 Thread Alex Parrill via Digitalmars-d-learn
On Thursday, 9 July 2015 at 17:11:36 UTC, Per Nordlöw wrote: On Thursday, 9 July 2015 at 16:12:27 UTC, Timon Gehr wrote: No. You'll need explicit pass by reference on the D side. So, how should I modify my call to `image_copy` with respect to the four first parameters? In C, array parameter

Re: Fixed Length Array Syntax in extern(C) Function Signatures

2015-07-09 Thread via Digitalmars-d-learn
On Thursday, 9 July 2015 at 16:12:27 UTC, Timon Gehr wrote: No. You'll need explicit pass by reference on the D side. So, how should I modify my call to `image_copy` with respect to the four first parameters?

Re: Fixed Length Array Syntax in extern(C) Function Signatures

2015-07-09 Thread Timon Gehr via Digitalmars-d-learn
On 07/09/2015 05:19 PM, "Nordlöw" wrote: Given extern(C): struct AVFrame { uint8_t*[AV_NUM_DATA_POINTERS] data; int[AV_NUM_DATA_POINTERS] linesize; int width, height; ... } void av_image_copy(ubyte *[4] dst_d

Re: Fixed Length Array Syntax in extern(C) Function Signatures

2015-07-09 Thread Nordlöw
On Thursday, 9 July 2015 at 15:19:41 UTC, Nordlöw wrote: uint8_t*[AV_NUM_DATA_POINTERS] data; int[AV_NUM_DATA_POINTERS] linesize; Forgot enum AV_NUM_DATA_POINTERS = 8;

Fixed Length Array Syntax in extern(C) Function Signatures

2015-07-09 Thread Nordlöw
Given extern(C): struct AVFrame { uint8_t*[AV_NUM_DATA_POINTERS] data; int[AV_NUM_DATA_POINTERS] linesize; int width, height; ... } void av_image_copy(ubyte *[4] dst_data, int[4] dst_linesizes, const ubyte *[4] src_data

Re: extern(C++) linker errors

2015-04-22 Thread bitwise via Digitalmars-d-learn
On Wed, 22 Apr 2015 02:14:40 -0400, Dan Olson wrote: bitwise writes: I am trying to interface to C++, and getting linker errors. Below are my 3 source files and 2 build scripts with their associated errors. Can anyone see what I'm doing wrong? Hi, I think both examples need libstdc++ adde

Re: extern(C++) linker errors

2015-04-21 Thread Dan Olson via Digitalmars-d-learn
bitwise writes: > I am trying to interface to C++, and getting linker errors. Below are > my 3 source files and 2 build scripts with their associated > errors. Can anyone see what I'm doing wrong? Hi, I think both examples need libstdc++ added when you link (-L-lstdc++). That should resolve the

extern(C++) linker errors

2015-04-21 Thread bitwise via Digitalmars-d-learn
d Foo(){ printf("Foobar\n"); } }; Test* CreateTest() { return new Test; } void DestroyTest(Test *test) { delete test; } / Test.d module TestMod; extern(C++) { interface Test { void Foo(); } Test CreateTest(

Re: Should this work: export extern(C) auto ...

2015-03-20 Thread Robert M. Münch via Digitalmars-d-learn
On 2015-03-19 13:22:44 +, Benjamin Thaut said: Generally don't expect to many things to work with DLLs at the moment. Hi, well, I think what's available is good enough to get most things done. Generally speaking only exporting global functions works. Don't try to export classes / structs

Re: Should this work: export extern(C) auto ...

2015-03-19 Thread Benjamin Thaut via Digitalmars-d-learn
On Thursday, 19 March 2015 at 12:58:42 UTC, Robert M. Münch wrote: On 2015-03-18 21:50:39 +, Adam D. Ruppe said: It will not work because a function with an auto return value is actually a template, and unused templates won't be put into a dll. Ok, that makes it clear. Thanks. Generall

Re: Should this work: export extern(C) auto ...

2015-03-19 Thread Robert M. Münch via Digitalmars-d-learn
On 2015-03-18 21:50:39 +, Adam D. Ruppe said: It will not work because a function with an auto return value is actually a template, and unused templates won't be put into a dll. Ok, that makes it clear. Thanks. -- Robert M. Münch http://www.saphirion.com smarter | better | faster

Re: Should this work: export extern(C) auto ...

2015-03-18 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 18 March 2015 at 15:50:16 UTC, Robert M. Münch wrote: struct1 is visible in the DLL, struct2 is not visible in the DLL. It will not work because a function with an auto return value is actually a template, and unused templates won't be put into a dll.

Should this work: export extern(C) auto ...

2015-03-18 Thread Robert M. Münch via Digitalmars-d-learn
Windows, 32-Bit, DLL: export extern(C) struct1 struct1(){ struct1 x; return(x); } export extern(C) auto struct2(){ struct1 x; return(x); } struct1 is visible in the DLL, struct2 is not visible in the DLL. -- Robert M. Münch http://www.saphirion.com smarter | better | faster

each extern (C) keyword causes ld (OS X) to add a duplicate library entry

2015-02-19 Thread Ernest Bruce via Digitalmars-d-learn
T/cprog-897189.o /usr/lib/libSystem.dylib /usr/lib/system/libcache.dylib /usr/lib/system/libcommonCrypto.dylib ... dprog.a(dprog_1_487.o) dprog.a(dprog_2_495.o) cprog.c includes two symbols exported from dprog.a, which uses the extern(C) keyword on the two functions exported from dprog.a wh

Re: Need extern (C) interface even though using Derelict GLFW

2015-01-04 Thread Mike Parker via Digitalmars-d-learn
is is a binding extern( C ) void do_something( const( char )* str ); // capiwrapper.d -- this is a wrapper void doSomething( string str ) { import std.string : toStringz; do_something( str.toStringz() ); } That's all there is to it. The binding allows you to call C functions from D

Re: Need extern (C) interface even though using Derelict GLFW

2015-01-04 Thread Rikki Cattermole via Digitalmars-d-learn
being passed to a C API, they *have* to be extern( C ) -- i.e. they have to have the same calling convention that the C library expects. If the library functions used the stdcall calling convention rather than cdecl, then the callbacks would have to be extern( Windows ). So even a wrapper that allow

Re: Need extern (C) interface even though using Derelict GLFW

2015-01-04 Thread WhatMeWorry via Digitalmars-d-learn
to be extern( C ) -- i.e. they have to have the same calling convention that the C library expects. If the library functions used the stdcall calling convention rather than cdecl, then the callbacks would have to be extern( Windows ). So even a wrapper that allows you to pass D delegates or fun

Re: Need extern (C) interface even though using Derelict GLFW

2015-01-04 Thread Mike Parker via Digitalmars-d-learn
On 1/4/2015 1:34 PM, WhatMeWorry wrote: Maybe GLFW callback functions can't handled through Derelict GLFW? And just to be clear, because the pointers to the callback functions are being passed to a C API, they *have* to be extern( C ) -- i.e. they have to have the same calling conve

Re: Need extern (C) interface even though using Derelict GLFW

2015-01-04 Thread Mike Parker via Digitalmars-d-learn
On 1/4/2015 1:34 PM, WhatMeWorry wrote: Now it resizes the screen successfully, but I feel like I've failed by using extern (C) nothrow. Shouldn't Derelict GLFW be providing a D interface? Maybe GLFW callback functions can't handled through Derelict GLFW? Derelict provides

Re: Need extern (C) interface even though using Derelict GLFW

2015-01-03 Thread Rikki Cattermole via Digitalmars-d-learn
indowResizeCallback); however, I kept getting the following compiler error: Error1Error: function pointer glfwSetWindowSizeCallback (GLFWwindow*, extern (C) void function(GLFWwindow*, int, int) nothrow) is not callable using argument types (GLFWwindow*, void function(GLFWwindow* window, in

Need extern (C) interface even though using Derelict GLFW

2015-01-03 Thread WhatMeWorry via Digitalmars-d-learn
I kept getting the following compiler error: Error 1 Error: function pointer glfwSetWindowSizeCallback (GLFWwindow*, extern (C) void function(GLFWwindow*, int, int) nothrow) is not callable using argument types (GLFWwindow*, void function(GLFWwindow* window, int width, int height)) Well, I was able t

Re: Problem calling extern(C) function

2014-12-15 Thread AuoroP via Digitalmars-d-learn
Thank you!!! All I have to do is > -Original Message- > From: digitalmars-d-learn@puremagic.com > Sent: Mon, 15 Dec 2014 17:54:51 + > To: digitalmars-d-learn@puremagic.com > Subject: Re: Problem calling extern(C) function > > On Monday, 15 December 2014 at 17:

Re: Problem calling extern(C) function

2014-12-15 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 15 December 2014 at 17:48:32 UTC, AuoroP via Digitalmars-d-learn wrote: ulong jpegSize, Without looking too closely, this sets off an alarm to me: C's long and D's long are not really compatible because C's long has variable size and D's long is 64 bit. I'd say try "import co

Problem calling extern(C) function

2014-12-15 Thread AuoroP via Digitalmars-d-learn
. I don't that is me because I call with extern(C) my .lst names are not mangled that way: _tjDecompressHeader2, _tjGetErrorStr, _tjInitDecompress. Even if you can't help, Thanks for reading this far! This message is kinda long so here's a TOC The code The output DL

Re: Wrapping multiple extern (C) declarations in a template

2014-12-14 Thread via Digitalmars-d-learn
On Saturday, 13 December 2014 at 19:03:42 UTC, aldanor wrote: If I now want to have exactly the same module but with all function declarations wrapped as described above, I have to public import it in another module and then do some template magic. However, it wouldn't be possible to retain the

Re: Wrapping multiple extern (C) declarations in a template

2014-12-13 Thread Mike Parker via Digitalmars-d-learn
On 12/14/2014 4:03 AM, aldanor wrote: However, it wouldn't be possible to retain the same function names since they've been imported to the namespace (it's then also not possible to extern them as private initially since then you won't be able to import/wrap them in a different module). Hence t

Re: Wrapping multiple extern (C) declarations in a template

2014-12-13 Thread Gary Willoughby via Digitalmars-d-learn
On Saturday, 13 December 2014 at 19:03:42 UTC, aldanor wrote: Let's say there's a "foo.d" that contains raw bindings to "foo.h" (enums, structs, extern variables, function declarations, a whole load of stuff) -- everything but the functions is already fine but all functions need to be wrapped.

Re: Wrapping multiple extern (C) declarations in a template

2014-12-13 Thread aldanor via Digitalmars-d-learn
Personally i wouldn't go this route. I would create foo.d as a C to D translation only so it can be imported and used like in C. Then i would create another module which imports this to create your new OOP API adding features and excepions, etc. This allows the best of both worlds, keep the C

Re: Wrapping multiple extern (C) declarations in a template

2014-12-13 Thread Gary Willoughby via Digitalmars-d-learn
d then gets the exception info via C API). My current naive solution looks like this: /* foo.h */ int f1(...); int f2(...); *** foo.d *** private extern (C) nothrow { pragma(mangle, "f1") int c_f(...); public alias errorCheck!c_f1 f1; pragma(mangle, "f2")

Wrapping multiple extern (C) declarations in a template

2014-12-13 Thread aldanor via Digitalmars-d-learn
rent naive solution looks like this: /* foo.h */ int f1(...); int f2(...); *** foo.d *** private extern (C) nothrow { pragma(mangle, "f1") int c_f(...); public alias errorCheck!c_f1 f1; pragma(mangle, "f2") int c_f2(...); public alias errorCheck!c_f2 f2; } This w

Re: alias and extern(C)

2014-10-30 Thread Laeeth Isharc via Digitalmars-d-learn
The code below works fine if you remove the extern(C). But I get the error "functionpointertest.d(6): Error: basic type expected, not extern" with the code as it is. How do I use alias with extern ? [...] alias Callback= extern(C) void function(int); Compiles as is with dmd

Re: alias and extern(C)

2014-10-30 Thread anonymous via Digitalmars-d-learn
On Thursday, 30 October 2014 at 18:43:21 UTC, Laeeth Isharc wrote: The code below works fine if you remove the extern(C). But I get the error "functionpointertest.d(6): Error: basic type expected, not extern" with the code as it is. How do I use alias with extern ? [...] alia

alias and extern(C)

2014-10-30 Thread Laeeth Isharc via Digitalmars-d-learn
Hi. I am trying to translate the following from the Dart header: typedef void (*Dart_MessageNotifyCallback)(Dart_Isolate dest_isolate); So I made a little simple test to understand callbacks in D. The code below works fine if you remove the extern(C). But I get the error

Re: extern (C) function call with const char * type will sometimes generate seg fault or core dump.

2014-10-16 Thread dysmondad via Digitalmars-d-learn
On Thursday, 16 October 2014 at 07:55:24 UTC, Mike Parker wrote: On 10/16/2014 4:54 PM, Mike Parker wrote: On 10/16/2014 12:18 PM, dysmondad wrote: Since I've added this call, my program will sometimes but not always either generate a core dump or a seg fault. It seems that the issue is with

Re: extern (C) function call with const char * type will sometimes generate seg fault or core dump.

2014-10-16 Thread Mike Parker via Digitalmars-d-learn
On 10/16/2014 4:54 PM, Mike Parker wrote: On 10/16/2014 12:18 PM, dysmondad wrote: Since I've added this call, my program will sometimes but not always either generate a core dump or a seg fault. It seems that the issue is with the const char * parameter. I don't have a good grasp of the differ

Re: extern (C) function call with const char * type will sometimes generate seg fault or core dump.

2014-10-16 Thread Mike Parker via Digitalmars-d-learn
On 10/16/2014 12:18 PM, dysmondad wrote: Since I've added this call, my program will sometimes but not always either generate a core dump or a seg fault. It seems that the issue is with the const char * parameter. I don't have a good grasp of the difference between the way D and C work for char

Re: extern (C) function call with const char * type will sometimes generate seg fault or core dump.

2014-10-16 Thread Ali Çehreli via Digitalmars-d-learn
ween the way D and C work > for char * types. The call to loadTexture uses a literal for the file > name, i.e. "resources/ball.png". > > // d lang bindings for C function > alias void SDL_Renderer; > alias void SDL_Texture; > extern (C) SDL_Texture * IMG_LoadTexture

extern (C) function call with const char * type will sometimes generate seg fault or core dump.

2014-10-15 Thread dysmondad via Digitalmars-d-learn
xture uses a literal for the file name, i.e. "resources/ball.png". // d lang bindings for C function alias void SDL_Renderer; alias void SDL_Texture; extern (C) SDL_Texture * IMG_LoadTexture(SDL_Renderer * renderer, const char * file); // d lang call to extern (C) function SDL_

extern(C) function declaration inside a function without altering mangling

2014-09-06 Thread Timothee Cour via Digitalmars-d-learn
Is there way to declare a extern(C) function inside a function without altering the mangled name? Should I write a mixin for that based on pragma(mangleof) (used as extern_C_global_scope in example below) ? Or did someone already implement that? extern(C) void foo1(); void fun(){ extern(C) void

Re: extern (c++) std::function?

2014-08-16 Thread Etienne via Digitalmars-d-learn
On 2014-08-15 6:12 AM, Rémy Mouëza wrote: assignments of anonymous/inline ones. You may want to add a layer of abstraction to the API you expose in D so that user D delegates are used from a second extern (C) delegate itself used by the C++ wrapper: Thanks for the detailed answer, this is the

Re: extern (c++) std::function?

2014-08-15 Thread Rémy Mouëza via Digitalmars-d-learn
otice -- althought it hasn't changed in many years): /* === */ /// ddg.d import std.stdio; import std.string; /// A C++ function that will take a D delegate. extern (C) void callDg (immutable(char)* delegate (int, int)); /// A dummy clas

Re: extern (c++) std::function?

2014-08-15 Thread FreeSlave via Digitalmars-d-learn
On Friday, 15 August 2014 at 03:10:43 UTC, Etienne Cimon wrote: I'm looking into making a binding for the C++ API called Botan, and the constructors in it take a std::function. I'm wondering if there's a D equivalent for this binding to work out, or if I have to make a C++ wrapper as well? Th

extern (c++) std::function?

2014-08-14 Thread Etienne Cimon via Digitalmars-d-learn
I'm looking into making a binding for the C++ API called Botan, and the constructors in it take a std::function. I'm wondering if there's a D equivalent for this binding to work out, or if I have to make a C++ wrapper as well?

Re: extern (C++, N) is it implemented?

2014-08-06 Thread hane via Digitalmars-d-learn
On Wednesday, 6 August 2014 at 06:50:59 UTC, Alexandr Druzhinin wrote: This dlang.org/cpp_interface.html says I can do the following // c++ namespace N { void someCppFunction(); } // d extern (C++, N) void someCppFunction(); but this http://dpaste.dzfl.pl/e2242263e1dc says I can'

Re: extern (C++, N) is it implemented?

2014-08-06 Thread Alexandr Druzhinin via Digitalmars-d-learn
06.08.2014 10:54, Dicebot пишет: On Wednesday, 6 August 2014 at 06:50:59 UTC, Alexandr Druzhinin wrote: This dlang.org/cpp_interface.html says I can do the following // c++ namespace N { void someCppFunction(); } // d extern (C++, N) void someCppFunction(); but this http://dpaste.dzfl.pl

extern (C++, N) is it implemented?

2014-08-05 Thread Alexandr Druzhinin via Digitalmars-d-learn
This dlang.org/cpp_interface.html says I can do the following // c++ namespace N { void someCppFunction(); } // d extern (C++, N) void someCppFunction(); but this http://dpaste.dzfl.pl/e2242263e1dc says I can't Is this feature implemented?

Re: extern (C++, N) is it implemented?

2014-08-05 Thread Dicebot via Digitalmars-d-learn
On Wednesday, 6 August 2014 at 06:50:59 UTC, Alexandr Druzhinin wrote: This dlang.org/cpp_interface.html says I can do the following // c++ namespace N { void someCppFunction(); } // d extern (C++, N) void someCppFunction(); but this http://dpaste.dzfl.pl/e2242263e1dc says I can'

extern (C) Names & Signatures

2014-06-16 Thread Chris via Digitalmars-d-learn
I use a library written in C. There are these two functions 1. MyLib_Initialize(), an existing 3rd party function 2. my_lib_initialize(), my custom function On Linux (my main platform) it compiled and worked without an error. On Windows, however, implib printed a warning and said that two defi

Re: sending a delegate through extern (C)

2014-04-13 Thread Andrej Mitrovic
On Thursday, 27 March 2014 at 00:46:33 UTC, Etienne wrote: Hi, I'm trying to send a delegate to a modified version of druntime's GC as follows: struct GC { static void onCollect(void* dg) { gc_onCollect(cast(void*)dg); } There isn't enough information

sending a delegate through extern (C)

2014-03-26 Thread Etienne
Hi, I'm trying to send a delegate to a modified version of druntime's GC as follows: struct GC { static void onCollect(void* dg) { gc_onCollect(cast(void*)dg); } ... my code: extern (C) extern __gshared void collecting(void* p,

Re: extern(C) function literals for stubs

2014-01-22 Thread Marco Leise
Am Wed, 22 Jan 2014 17:52:03 + schrieb "bearophile" : > Marco Leise: > > > Can I define them somehow? The use case is defining extern C > > functions that contain code to load the real thing from a > > library. > > > > nothrow extern(C) void

Re: extern(C) function literals for stubs

2014-01-22 Thread Marco Leise
Am Wed, 22 Jan 2014 17:52:03 + schrieb "bearophile" : > Marco Leise: > > > Can I define them somehow? The use case is defining extern C > > functions that contain code to load the real thing from a > > library. > > > > nothrow extern(C) void

Re: extern(C) function literals for stubs

2014-01-22 Thread bearophile
Marco Leise: Can I define them somehow? The use case is defining extern C functions that contain code to load the real thing from a library. nothrow extern(C) void function(int) someFunc = ??? Perhaps you want: extern(C) nothrow void someFunc(int someArg); Bye, bearophile

extern(C) function literals for stubs

2014-01-22 Thread Marco Leise
Can I define them somehow? The use case is defining extern C functions that contain code to load the real thing from a library. nothrow extern(C) void function(int) someFunc = ??? -- Marco

Re: extern(C) function declarations and extra keywords.

2014-01-19 Thread Jacob Carlborg
On 2013-12-28 22:47, Jeremy DeHaan wrote: Since the C functions can't access anything from D code save for what is passed through as parameters, can it be called pure? And if so, does the compiler know how to distinguish C and D in this instance and make it inherently pure? Does purity do anythi

Re: Shared library extern (C) variables

2014-01-06 Thread TheFlyingFiddle
On Monday, 6 January 2014 at 09:27:26 UTC, Jacob Carlborg wrote: To be able to load symbols from libraries at runtime they have to be declared with extern. "export", not "extern". Yeah typo sry.

Re: Shared library extern (C) variables

2014-01-06 Thread Jacob Carlborg
On 2014-01-05 22:15, TheFlyingFiddle wrote: Export is currently somewhat broken see DIP45 for an indepth explanation (link) To be able to load symbols from libraries at runtime they have to be declared with extern. "export", not "extern". This rule does not hold on linux though since it sim

Re: Shared library extern (C) variables

2014-01-05 Thread TheFlyingFiddle
o for instance: void foo() { ... } //This will NOT be avalible for loading under windows. export void foo() { ... } //This is avalible for loading under windows. extern(C) void foo() { ... } //This will also not be avalible for loading. extern is a whole diffrent creature. extern deals with

Re: Shared library extern (C) variables

2014-01-05 Thread Jeremy DeHaan
On Sunday, 5 January 2014 at 19:55:50 UTC, Mineko wrote: On Sunday, 5 January 2014 at 19:47:46 UTC, FreeSlave wrote: Some code snippets of what you try to do would help. Maybe this example explain you something: //mod.d extern(C) int foo = 42; void changeFoo(int val) { foo = val

Re: Shared library extern (C) variables

2014-01-05 Thread Mineko
On Sunday, 5 January 2014 at 19:47:46 UTC, FreeSlave wrote: Some code snippets of what you try to do would help. Maybe this example explain you something: //mod.d extern(C) int foo = 42; void changeFoo(int val) { foo = val; } //main.d import std.stdio; import mod; int main

Re: Shared library extern (C) variables

2014-01-05 Thread FreeSlave
On Sunday, 5 January 2014 at 18:22:54 UTC, Mineko wrote: I keep getting mixed results searching for this. :\ Just as the title says, is it safe to extern (C) variables? Something like this: extern (C) auto foo = 800; And then call that from another program? Also, just because this has been

Re: Shared library extern (C) variables

2014-01-05 Thread Mineko
On Sunday, 5 January 2014 at 19:08:44 UTC, Jeremy DeHaan wrote: On Sunday, 5 January 2014 at 18:22:54 UTC, Mineko wrote: I keep getting mixed results searching for this. :\ Just as the title says, is it safe to extern (C) variables? Something like this: extern (C) auto foo = 800; And then

Re: Shared library extern (C) variables

2014-01-05 Thread Jeremy DeHaan
On Sunday, 5 January 2014 at 18:22:54 UTC, Mineko wrote: I keep getting mixed results searching for this. :\ Just as the title says, is it safe to extern (C) variables? Something like this: extern (C) auto foo = 800; And then call that from another program? Also, just because this has been

Shared library extern (C) variables

2014-01-05 Thread Mineko
I keep getting mixed results searching for this. :\ Just as the title says, is it safe to extern (C) variables? Something like this: extern (C) auto foo = 800; And then call that from another program? Also, just because this has been bugging me for a while.. Is export broken, or it it not

Re: extern(C) function declarations and extra keywords.

2013-12-29 Thread Jakob Ovrum
On Sunday, 29 December 2013 at 14:50:52 UTC, H. S. Teoh wrote: Yes, since C code will not throw D exceptions (C doesn't know anything about D exceptions). Unless you pass in a function pointer to a D function that does throw an exception... but that case doesn't work for other reasons, so it ge

Re: extern(C) function declarations and extra keywords.

2013-12-29 Thread H. S. Teoh
On Sat, Dec 28, 2013 at 09:57:06PM +, ponce wrote: [...] > >I noticed that in Deimos and Derelict that most(if not all) C > >function declarations are marked as nothrow. What are the > >speed/safety benefits of including this? > > No speed or safety benefit, but it allows to call these C funct

Re: extern(C) function declarations and extra keywords.

2013-12-28 Thread ponce
ently nothrow? No. C's name mangling doesn't allow function overloading, but as far as I know you can overload extern(C) functions in D. Does adding final help with speed improvements in the D side of things if added to an extern(C) function declaration? No.

extern(C) function declarations and extra keywords.

2013-12-28 Thread Jeremy DeHaan
I was thinking of adding some keywords like final, pure, and nothrow in to my library to improve various things where improvements could be made. As I was thinking about this, I wondered about my extern(C) function declarations and how keywords could improve those as well. Since the C

Re: extern(C) delegate

2013-12-04 Thread Rémy Mouëza
// This calls the D delegate from C. // One has to pass dg.ctx as first argument. printf ("result: %s\n", dg.fn (dg.ctx, 42, 7)); } } } in D (ddg.d) { import std.stdio; import std.string; import std.conv; extern (C) void callDg (

extern(C) delegate

2013-12-04 Thread Mariusz `shd` Gliwiński
I'd like to expose my D API to C code. For that, i'm going to write templates generate extern(C) definition alongside of D-one. One thing i could do, is to generate D struct that mimics delegate with appropriate arguments. However, i'm curious of another possibility: How do

Re: extern(C) bool function type?

2013-09-26 Thread Charles Hixson
I'd forgotten about: int_least8_t I guess that's what I should use. On 09/26/2013 03:06 PM, bearophile wrote: Charles Hixson: So... if C returns an int64_t and I declare it as an int32_t, will this cause problems? What about if C returns an int32_t and I declare it as an int64_t?

<    1   2   3   4   >