Re: Vibe-d issue with timer in separate thread on debug builds

2018-01-18 Thread Andres Clari via Digitalmars-d-learn
On Thursday, 18 January 2018 at 10:03:57 UTC, drug wrote: 18.01.2018 08:45, Andres Clari пишет: I see, then although it works (or it may work) on release shouldn't that assert happen for release builds by default too? Or is the thought that you got the error running the debug build you shoul

Re: __gshared as part of alias

2018-01-18 Thread Johan Engelen via Digitalmars-d-learn
On Wednesday, 17 January 2018 at 22:56:09 UTC, kinke wrote: On Wednesday, 17 January 2018 at 22:01:57 UTC, Johan Engelen wrote: ``` struct GSharedVariable(AddrSpace as, T) { static __gshared T val; alias val this; } alias Global(T) = GSharedVariable!(AddrSpace.Global, T); Global!flo

Re: New integer promotion rules

2018-01-18 Thread rumbu via Digitalmars-d-learn
On Thursday, 18 January 2018 at 18:00:51 UTC, rumbu wrote: On Thursday, 18 January 2018 at 17:54:59 UTC, rumbu wrote: On Thursday, 18 January 2018 at 12:51:48 UTC, Dominikus Dittes target = isNegative ? cast(Unsigned!T)(-c) : cast(Unsigned!T)c; That would have been better even before the

Re: New integer promotion rules

2018-01-18 Thread rumbu via Digitalmars-d-learn
On Thursday, 18 January 2018 at 17:54:59 UTC, rumbu wrote: On Thursday, 18 January 2018 at 12:51:48 UTC, Dominikus Dittes target = isNegative ? cast(Unsigned!T)(-c) : cast(Unsigned!T)c; That would have been better even before the change, because the operator '-' used on unsigned types is li

Re: New integer promotion rules

2018-01-18 Thread rumbu via Digitalmars-d-learn
On Thursday, 18 January 2018 at 12:51:48 UTC, Dominikus Dittes Scherkl wrote: On Thursday, 18 January 2018 at 06:05:08 UTC, rumbu wrote: On Thursday, 18 January 2018 at 02:30:17 UTC, Rubn wrote: On Wednesday, 17 January 2018 at 22:30:11 UTC, rumbu wrote: code like "m = n < 0 ? -n : n" doesn't

Re: cast ref pointer

2018-01-18 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 18 January 2018 at 16:26:54 UTC, Luís Marques wrote: The actual function bar also receives by ref its pointer. you might be better off receiving a pointer-to-pointer instead of ref. Then it will be encoded in the type and thus you can cast outer layers too and use intermediate mo

Re: Any sample how to use Sqlite-d?

2018-01-18 Thread biozic via Digitalmars-d-learn
On Wednesday, 17 January 2018 at 13:36:26 UTC, Marc wrote: I was looking for a library to use SQLite with D, found this (https://code.dlang.org/packages/sqlite-d) but it has no documentation or code example. I looked into files in the source code and wrote this: Database db = Database(name);

Re: New integer promotion rules

2018-01-18 Thread ag0aep6g via Digitalmars-d-learn
On 01/18/2018 05:22 PM, Steven Schveighoffer wrote: Sure, but what does the statement "Once deprecated this will become an error" mean? Will I have to use the -transition=intpromote switch forever to avoid an error? As you quoted before: "Once deprecated this will become an error, and then th

Re: cast ref pointer

2018-01-18 Thread Luís Marques via Digitalmars-d-learn
On Thursday, 18 January 2018 at 16:14:18 UTC, ag0aep6g wrote: On 01/18/2018 04:25 PM, Luís Marques wrote: You need a reinterpret-style cast here to get an lvalue: foo(* cast(int**) &ptr); Right, that's what I wanted. Ugh, for some reason I was totally confused about this :-)     w

Re: cast ref pointer

2018-01-18 Thread Luís Marques via Digitalmars-d-learn
On Thursday, 18 January 2018 at 16:20:35 UTC, Steven Schveighoffer wrote: Note, this, to me, seems odd. Of course this is not the full case, but you are not affecting anything except for the value of the local `ptr`. So I would be concerned this may not be what you want (if you are looking to a

Re: New integer promotion rules

2018-01-18 Thread Steven Schveighoffer via Digitalmars-d-learn
On 1/18/18 11:14 AM, ag0aep6g wrote: On 01/18/2018 03:30 PM, Steven Schveighoffer wrote: Is there going to be a point where casts aren't needed? Otherwise, this is pretty ugly. You don't need casts when you use `-transition=intpromote`. Sure, but what does the statement "Once deprecated this

Re: cast ref pointer

2018-01-18 Thread Luís Marques via Digitalmars-d-learn
On Thursday, 18 January 2018 at 16:08:32 UTC, Adam D. Ruppe wrote: Simply define an intermediate. int* tmp = cast(int*) that_void_pointer; foo(tmp); In my actual case bar also receives its pointer by ref, so you would have to do something like: int* tmp = cast(int*) that_void_pointer; foo(t

Re: cast ref pointer

2018-01-18 Thread Steven Schveighoffer via Digitalmars-d-learn
On 1/18/18 10:25 AM, Luís Marques wrote: This works, obviously (i.e. it prints 42):     void foo(ref int* a)     {     static int j = 42;     a = &j;     }     void bar(int* ptr)     {     foo(ptr);     writeln(*ptr);     } Note, this, to me, seems odd. Of course thi

Re: New integer promotion rules

2018-01-18 Thread ag0aep6g via Digitalmars-d-learn
On 01/18/2018 03:30 PM, Steven Schveighoffer wrote: Is there going to be a point where casts aren't needed? Otherwise, this is pretty ugly. You don't need casts when you use `-transition=intpromote`.

Re: cast ref pointer

2018-01-18 Thread ag0aep6g via Digitalmars-d-learn
On 01/18/2018 04:25 PM, Luís Marques wrote: This works, obviously (i.e. it prints 42):     void foo(ref int* a)     {     static int j = 42;     a = &j;     }     void bar(int* ptr)     {     foo(ptr);     writeln(*ptr);     }     void main()     {     int i =

Re: cast ref pointer

2018-01-18 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 18 January 2018 at 15:25:38 UTC, Luís Marques wrote: I think the underlying idea is sound (use ptr as an lvalue, but with int* type), but since you can't cast(ref int*), I don't know how to express it in D code. Simply define an intermediate. int* tmp = cast(int*) that_void_point

cast ref pointer

2018-01-18 Thread Luís Marques via Digitalmars-d-learn
This works, obviously (i.e. it prints 42): void foo(ref int* a) { static int j = 42; a = &j; } void bar(int* ptr) { foo(ptr); writeln(*ptr); } void main() { int i = 7; bar(&i); } Unfortunately, if bar for some

Re: New integer promotion rules

2018-01-18 Thread Steven Schveighoffer via Digitalmars-d-learn
On 1/17/18 2:40 PM, rumbu wrote: This started in the last DMD version (2.078): byte b = -10; ulong u = b < 0 ? -b : b; //Deprecation: integral promotion not done for `-b`, use '-transition=intpromote' switch or `-cast(int)(b) Why do I need a to promote a byte to int to obtain an ulong? Even

Re: New integer promotion rules

2018-01-18 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Thursday, 18 January 2018 at 06:05:08 UTC, rumbu wrote: On Thursday, 18 January 2018 at 02:30:17 UTC, Rubn wrote: On Wednesday, 17 January 2018 at 22:30:11 UTC, rumbu wrote: code like "m = n < 0 ? -n : n" doesn't worth a wrapper That code is worth a wrapper, it's called "abs"... m = abs(n

Re: Vibe-d issue with timer in separate thread on debug builds

2018-01-18 Thread drug via Digitalmars-d-learn
18.01.2018 08:45, Andres Clari пишет: I see, then although it works (or it may work) on release shouldn't that assert happen for release builds by default too? Or is the thought that you got the error running the debug build you should do it a different way on your own and skip the check all