Re: Seg fault when calling C code

2014-05-20 Thread Kagamin via Digitalmars-d-learn
On Friday, 16 May 2014 at 14:52:17 UTC, Marc Schütz wrote: But that's extern(C++), not extern(C)... That should be a different name mangling, so won't link. Winapi functions are declared as extern C for C++ compiler.

Seeking Advice on D Bindings for Large C Library Collection

2014-05-20 Thread Tom Browder via Digitalmars-d-learn
I am working on a project to provide D binding files for the C/C++ FOSS BRL-CAD project: http://brlcad.org My work is on the d-binding branch and specifically here: http://sourceforge.net/p/brlcad/code/HEAD/tree/brlcad/branches/d-binding/misc/d-bindings/ My plan is to automatically

Re: Seeking Advice on D Bindings for Large C Library Collection

2014-05-20 Thread Rikki Cattermole via Digitalmars-d-learn
On 20/05/2014 10:36 p.m., Tom Browder via Digitalmars-d-learn wrote: I am working on a project to provide D binding files for the C/C++ FOSS BRL-CAD project: http://brlcad.org My work is on the d-binding branch and specifically here:

Question about @nogc

2014-05-20 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
Did I understand correct that a function can only be @nogc if also all functions that it calls are @nogc too (and of course it doesn't use the GC itself)? If so, should this be possible: string foo() { // use GC to allocate some string } bar @nogc { mixin(foo()); } Because, bar()

Re: Question about @nogc

2014-05-20 Thread monarch_dodra via Digitalmars-d-learn
On Tuesday, 20 May 2014 at 12:25:11 UTC, Dominikus Dittes Scherkl wrote: Did I understand correct that a function can only be @nogc if also all functions that it calls are @nogc too (and of course it doesn't use the GC itself)? If so, should this be possible: string foo() { // use GC to

[std.c.stdlib] (malloc(something) is null) or (malloc(something) == 0)?

2014-05-20 Thread Alexandr Druzhinin via Digitalmars-d-learn
In D code I do void* data = GC.malloc(...); if(data is null) ... In C code I do void* data = malloc(...); if(data == null) ... What to do when in D code I have void* data = std.c.stdlib.malloc(...); if(data ?) // is null vs == 0

Re: [std.c.stdlib] (malloc(something) is null) or (malloc(something) == 0)?

2014-05-20 Thread bearophile via Digitalmars-d-learn
Alexandr Druzhinin: In D code I do void* data = GC.malloc(...); if(data is null) ... In C code I do void* data = malloc(...); if(data == null) ... What to do when in D code I have void* data = std.c.stdlib.malloc(...); if(data ?) // is null vs == 0 x is null or x == null are

Re: [std.c.stdlib] (malloc(something) is null) or (malloc(something) == 0)?

2014-05-20 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 20 May 2014 at 14:03:17 UTC, Alexandr Druzhinin wrote: if(data ?) // is null vs == 0 Both would work and do the same thing, but I prefer is null because that is most consistent with other D code (where there might be a difference between the two).

Re: [std.c.stdlib] (malloc(something) is null) or (malloc(something) == 0)?

2014-05-20 Thread bearophile via Digitalmars-d-learn
Adam D. Ruppe: but I prefer is null because that is most consistent with other D code (where there might be a difference between the two). Curiously I do the opposite, I use == to remind me it's a pointer :-) Bye, bearophile

Re: Question about @nogc

2014-05-20 Thread John Colvin via Digitalmars-d-learn
On Tuesday, 20 May 2014 at 12:25:11 UTC, Dominikus Dittes Scherkl wrote: Did I understand correct that a function can only be @nogc if also all functions that it calls are @nogc too (and of course it doesn't use the GC itself)? If so, should this be possible: string foo() { // use GC to

byCodePoint for a range of chars

2014-05-20 Thread John Colvin via Digitalmars-d-learn
Given a range with element type char, what's the best way of iterating over it by code-point, without filling an array first? Related to this: What's the status of std.utf and std.encoding? The comments in std.encoding say that some functions supersede their std.utf counterparts.

Re: byCodePoint for a range of chars

2014-05-20 Thread Justin Whear via Digitalmars-d-learn
On Tue, 20 May 2014 17:59:07 +, John Colvin wrote: Given a range with element type char, what's the best way of iterating over it by code-point, without filling an array first? Related to this: What's the status of std.utf and std.encoding? The comments in std.encoding say that some

std.concurrency bug?

2014-05-20 Thread Charles Hixson via Digitalmars-d-learn
Is it a bug that an immutable struct cannot be sent to a thread? (It compiles without problem if I make all elements mutable.)

Re: std.concurrency bug?

2014-05-20 Thread Ali Çehreli via Digitalmars-d-learn
On 05/20/2014 11:38 AM, Charles Hixson via Digitalmars-d-learn wrote: Is it a bug that an immutable struct cannot be sent to a thread? (It compiles without problem if I make all elements mutable.) Does the struct have any mutable indirection? Then it is illegal. Otherwise, can you

Re: byCodePoint for a range of chars

2014-05-20 Thread monarch_dodra via Digitalmars-d-learn
On Tuesday, 20 May 2014 at 17:59:09 UTC, John Colvin wrote: Given a range with element type char, what's the best way of iterating over it by code-point, without filling an array first? Related to this: What's the status of std.utf and std.encoding? The comments in std.encoding say that some

Re: byCodePoint for a range of chars

2014-05-20 Thread monarch_dodra via Digitalmars-d-learn
On Tuesday, 20 May 2014 at 18:06:09 UTC, Justin Whear wrote: Foreach on narrow strings automatically decodes, so it's as simple as: // assume UTF-8 encoded char[] myData = ... foreach (dchar codePoint; myData) ... I think the point of his question is if you have an actual non-array range

Re: Question about @nogc

2014-05-20 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Tuesday, 20 May 2014 at 17:14:31 UTC, John Colvin wrote: On Tuesday, 20 May 2014 at 12:25:11 UTC, Dominikus Dittes Scherkl wrote: Did I understand correct that a function can only be @nogc if also all functions that it calls are @nogc too (and of course it doesn't use the GC itself)? If

Re: Question about @nogc

2014-05-20 Thread anonymous via Digitalmars-d-learn
On Tuesday, 20 May 2014 at 20:15:09 UTC, Dominikus Dittes Scherkl wrote: /// create a fixed size array with the given name and with *max* entries max + 1 entries /// of immutable values of the same type as the return value of the /// given function. /// it contains the values of that

Re: Question about @nogc

2014-05-20 Thread monarch_dodra via Digitalmars-d-learn
On Tuesday, 20 May 2014 at 21:04:37 UTC, anonymous wrote: On Tuesday, 20 May 2014 at 20:15:09 UTC, Dominikus Dittes Scherkl wrote: /// create a fixed size array with the given name and with *max* entries max + 1 entries /// of immutable values of the same type as the return value of the

Re: Question about @nogc

2014-05-20 Thread anonymous via Digitalmars-d-learn
On Tuesday, 20 May 2014 at 21:16:26 UTC, monarch_dodra wrote: enum ReturnType!fn[length] lookupTable = [elements]; Depending on what the usecase is, you might want to change that to static immutable instead: static immutable ReturnType!fn[length] lookupTable = [elements]; Remember that

Re: Question about @nogc

2014-05-20 Thread Timon Gehr via Digitalmars-d-learn
On 05/20/2014 11:04 PM, anonymous wrote: On Tuesday, 20 May 2014 at 20:15:09 UTC, Dominikus Dittes Scherkl wrote: /// create a fixed size array with the given name and with *max* entries max + 1 entries /// of immutable values of the same type as the return value of the /// given function.

Re: Question about @nogc

2014-05-20 Thread Timon Gehr via Digitalmars-d-learn
On 05/20/2014 11:48 PM, Timon Gehr wrote: This achieves the same: template lookupTable(alias fn,uint max=255){ static assert(maxuint.max); enum ReturnType!fn[max+1] lookupTable=iota(0,max+1).map!fn.array; } (Though I'd never actually do template argument checking in a static

Re: Question about @nogc

2014-05-20 Thread anonymous via Digitalmars-d-learn
On Tuesday, 20 May 2014 at 21:48:08 UTC, Timon Gehr wrote: Wtf. Is this really the point you are trying to make? :o) This achieves the same: template lookupTable(alias fn,uint max=255){ static assert(maxuint.max); enum ReturnType!fn[max+1] lookupTable=iota(0,max+1).map!fn.array; }

Re: byCodePoint for a range of chars

2014-05-20 Thread John Colvin via Digitalmars-d-learn
On Tuesday, 20 May 2014 at 19:58:17 UTC, monarch_dodra wrote: On Tuesday, 20 May 2014 at 17:59:09 UTC, John Colvin wrote: Given a range with element type char, what's the best way of iterating over it by code-point, without filling an array first? Related to this: What's the status of

Re: std.concurrency bug?

2014-05-20 Thread Charles Hixson via Digitalmars-d-learn
On Tuesday, May 20, 2014 11:42:48 AM Ali Çehreli via Digitalmars-d-learn wrote: On 05/20/2014 11:38 AM, Charles Hixson via Digitalmars-d-learn wrote: Is it a bug that an immutable struct cannot be sent to a thread? (It compiles without problem if I make all elements mutable.) Does the

Re: std.concurrency bug?

2014-05-20 Thread Charles Hixson via Digitalmars-d-learn
On Tuesday, May 20, 2014 11:42:48 AM Ali Çehreli via Digitalmars-d-learn wrote: On 05/20/2014 11:38 AM, Charles Hixson via Digitalmars-d-learn wrote: Is it a bug that an immutable struct cannot be sent to a thread? (It compiles without problem if I make all elements mutable.) Does the