Can you fix this code to avoid using pointers?

2017-03-11 Thread XavierAP via Digitalmars-d-learn
I do not really think it's a bad solution, to check several scalar arguments that must obey the same condition; just wondering if you have better ideas. Try to avoid modifying the function's signature and defining custom types, unless you have a really terrific idea. void calc(double in1, dou

Re: Can you fix this code to avoid using pointers?

2017-03-11 Thread XavierAP via Digitalmars-d-learn
Oh... please forget it What a terrible example :p I forgot why I was using pointers at all... I must have had a reason to write this in the past ???

Re: Can you fix this code to avoid using pointers?

2017-03-11 Thread XavierAP via Digitalmars-d-learn
On Saturday, 11 March 2017 at 12:35:42 UTC, XavierAP wrote: I do not really think it's a bad solution, to check several scalar arguments that must obey the same condition; just wondering if you have better ideas. Try to avoid modifying the function's signature and defining custom types, unless

Re: Can you fix this code to avoid using pointers?

2017-03-11 Thread Satoshi via Digitalmars-d-learn
On Saturday, 11 March 2017 at 12:35:42 UTC, XavierAP wrote: I do not really think it's a bad solution, to check several scalar arguments that must obey the same condition; just wondering if you have better ideas. Try to avoid modifying the function's signature and defining custom types, unless

Re: Can you fix this code to avoid using pointers?

2017-03-11 Thread XavierAP via Digitalmars-d-learn
On Saturday, 11 March 2017 at 13:44:30 UTC, Satoshi wrote: void calc(in double[] array...) { foreach (x; array) { } } To do what I want it should be foreach(ref x; array) -- or const ref. But also I don't want to modify the function signature, certainly in this way. In another situation yes,

Re: Can you fix this code to avoid using pointers?

2017-03-11 Thread Adam D. Ruppe via Digitalmars-d-learn
On Saturday, 11 March 2017 at 14:49:42 UTC, XavierAP wrote: But also I don't want to modify the function signature, certainly in this way. It is already copied by the time you get in to the function though because of the signature (unless they are constructed in-place at the call site). But

Problem building DMD

2017-03-11 Thread Eric via Digitalmars-d-learn
I'm trying to build the master branch of DMD on redhat 7. I get the following errors: ddmd/root/newdelete.c:26:8: error: expected identifier or ‘(’ before string constant extern "C" ^ ddmd/root/newdelete.c:31:17: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘new’ v

Re: Problem building DMD

2017-03-11 Thread ag0aep6g via Digitalmars-d-learn
On 03/11/2017 06:41 PM, Eric wrote: I'm trying to build the master branch of DMD on redhat 7. I get the following errors: ddmd/root/newdelete.c:26:8: error: expected identifier or ‘(’ before string constant extern "C" ^ ddmd/root/newdelete.c:31:17: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ o

Re: DMD win32.mak error

2017-03-11 Thread Stefan Koch via Digitalmars-d-learn
On Saturday, 11 March 2017 at 02:25:15 UTC, Paul D Anderson wrote: On Saturday, 11 March 2017 at 00:34:03 UTC, Paul D Anderson wrote: On Friday, 10 March 2017 at 22:04:23 UTC, Paul D Anderson wrote: While building DMD -- "make -fwin32.mak release" -- I received the following error message: ec

Re: Problem building DMD

2017-03-11 Thread Eric via Digitalmars-d-learn
On Saturday, 11 March 2017 at 17:54:55 UTC, ag0aep6g wrote: Looks like a C compiler is used instead of a C++ compiler. Despite the extension, dmd's *.c files are C++ code. Yes, that's what I thought - redhat has gcc, but not g++. There must be a needed compile option...

Re: Problem building DMD

2017-03-11 Thread Eric via Digitalmars-d-learn
On Saturday, 11 March 2017 at 17:54:55 UTC, ag0aep6g wrote: On 03/11/2017 06:41 PM, Eric wrote: I'm trying to build the master branch of DMD on redhat 7. I get the following errors: ddmd/root/newdelete.c:26:8: error: expected identifier or ‘(’ before string constant extern "C" ^ ddmd

Re: Can you fix this code to avoid using pointers?

2017-03-11 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Mar 11, 2017 at 12:45:10PM +, XavierAP via Digitalmars-d-learn wrote: > On Saturday, 11 March 2017 at 12:35:42 UTC, XavierAP wrote: > > I do not really think it's a bad solution, to check several scalar > > arguments that must obey the same condition; just wondering if you > > have bet

Re: Can you fix this code to avoid using pointers?

2017-03-11 Thread XavierAP via Digitalmars-d-learn
On Saturday, 11 March 2017 at 19:15:59 UTC, H. S. Teoh wrote: What about just: foreach (const ref p; [in1, in2, in3, in4]) I would think there will be already one copy from the local parameter variables to the in situ array. Then from that one into the for each element it's ref'd al

C interface provides a pointer and a length... wrap without copying?

2017-03-11 Thread cy via Digitalmars-d-learn
So a lovely C library does its own opaque allocation, and provides access to the malloc'd memory, and that memory's length. Instead of copying the results into garbage collected memory (which would probably be smart) I was thinking about creating a structure like: struct WrappedString { byt

Re: C interface provides a pointer and a length... wrap without copying?

2017-03-11 Thread ketmar via Digitalmars-d-learn
cy wrote: So a lovely C library does its own opaque allocation, and provides access to the malloc'd memory, and that memory's length. Instead of copying the results into garbage collected memory (which would probably be smart) I was thinking about creating a structure like: struct WrappedStr

Dub and bindings

2017-03-11 Thread qznc via Digitalmars-d-learn
Are there any general tips or best practices for bindings in dub packages? For example, I love the d2sqlite3 package. It just works out of the box. No linker configuration or anything. However, that is probably a testament to sqlite's lack of dependencies. That cannot work for libraries, whic

Re: C interface provides a pointer and a length... wrap without copying?

2017-03-11 Thread Nicholas Wilson via Digitalmars-d-learn
On Saturday, 11 March 2017 at 22:39:02 UTC, cy wrote: So a lovely C library does its own opaque allocation, and provides access to the malloc'd memory, and that memory's length. Instead of copying the results into garbage collected memory (which would probably be smart) I was thinking about cr

Re: DMD win32.mak error

2017-03-11 Thread Paul D Anderson via Digitalmars-d-learn
On Saturday, 11 March 2017 at 18:02:00 UTC, Stefan Koch wrote: On Saturday, 11 March 2017 at 02:25:15 UTC, Paul D Anderson wrote: On Saturday, 11 March 2017 at 00:34:03 UTC, Paul D Anderson wrote: On Friday, 10 March 2017 at 22:04:23 UTC, Paul D Anderson wrote: [...] I see John Colvin has al

I think is a bug?

2017-03-11 Thread Random D user via Digitalmars-d-learn
int*[] foo; foo.length = 5; import std.c.string; int* baz = cast(string*)malloc(50); import std.c.stdio; printf("%d %d", foo.length, baz.length ); prints: Error: no property 'length' for type 'int*' BUT: string*[] foo; foo.length = 5; import std.c.string; string* baz = cast(string*)malloc(50

Re: I think is a bug?

2017-03-11 Thread ketmar via Digitalmars-d-learn
Random D user wrote: How come string* suddenly has a .length property? due to automatic pointer dereferencing that `.` does. no, not a bug.

Re: I think is a bug?

2017-03-11 Thread Random D user via Digitalmars-d-learn
On Sunday, 12 March 2017 at 01:55:20 UTC, ketmar wrote: Random D user wrote: How come string* suddenly has a .length property? due to automatic pointer dereferencing that `.` does. no, not a bug. Ah... right. Silly me. Of course, since string is actually immutable(char)[]. That's bit of a

Re: C interface provides a pointer and a length... wrap without copying?

2017-03-11 Thread cy via Digitalmars-d-learn
On Saturday, 11 March 2017 at 23:43:54 UTC, Nicholas Wilson wrote: A string *is* a pointer length pair, an immutable(char)[]. Yes, but surely there's some silly requirement, like that the pointer must only ever point to garbage collected memory, or something? ubyte[] arr; // or byte/char wh

Re: C interface provides a pointer and a length... wrap without copying?

2017-03-11 Thread ketmar via Digitalmars-d-learn
cy wrote: On Saturday, 11 March 2017 at 23:43:54 UTC, Nicholas Wilson wrote: A string *is* a pointer length pair, an immutable(char)[]. Yes, but surely there's some silly requirement, like that the pointer must only ever point to garbage collected memory, or something? why should it? a sli

Re: C interface provides a pointer and a length... wrap without copying?

2017-03-11 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, March 12, 2017 02:47:19 cy via Digitalmars-d-learn wrote: > On Saturday, 11 March 2017 at 23:43:54 UTC, Nicholas Wilson wrote: > > A string *is* a pointer length pair, an immutable(char)[]. > > Yes, but surely there's some silly requirement, like that the > pointer must only ever point t

Is there a more elegant way to do this?

2017-03-11 Thread bauss via Digitalmars-d-learn
I was wondering if there's a more elegant way to do something like this? template BitSize(T) { enum BitSize = T.sizeof * 8; } struct Data(ParentType,ChildType) { @property { ChildType low() { return cast(ChildType)value; } void low(ChildType lowVa

Re: Is there a more elegant way to do this?

2017-03-11 Thread bauss via Digitalmars-d-learn
On Sunday, 12 March 2017 at 05:13:41 UTC, bauss wrote: I was wondering if there's a more elegant way to do something like this? [...] I saw one improvement to it which would be BitSize!ChildType instead of taking parent type's bit size divided by two. Also value = ((highValue << 16 | low)

Re: Is there a more elegant way to do this?

2017-03-11 Thread Nicholas Wilson via Digitalmars-d-learn
On Sunday, 12 March 2017 at 05:13:41 UTC, bauss wrote: I was wondering if there's a more elegant way to do something like this? template BitSize(T) { enum BitSize = T.sizeof * 8; } struct Data(ParentType,ChildType) { @property { ChildType low() { return cast(Chi