Re: Problem with casting instance reference to void* and back.

2015-07-27 Thread anonymous via Digitalmars-d-learn
On Monday, 27 July 2015 at 12:03:06 UTC, Vlad Leberstein wrote: Hi! My use case requires interaction with C API which in turn implies storing object instance reference as void *. I'm using gdc 4.9.2 and everything worked fine with object - void * - object conversion, but object - void * -

Problem with casting instance reference to void* and back.

2015-07-27 Thread Vlad Leberstein via Digitalmars-d-learn
Hi! My use case requires interaction with C API which in turn implies storing object instance reference as void *. I'm using gdc 4.9.2 and everything worked fine with object - void * - object conversion, but object - void * - interface failed. The stripped-down example is something like this:

Re: Problem with casting instance reference to void* and back.

2015-07-27 Thread Artur Skawina via Digitalmars-d-learn
On 07/27/15 14:03, Vlad Leberstein via Digitalmars-d-learn wrote: Hi! My use case requires interaction with C API which in turn implies storing object instance reference as void *. I'm using gdc 4.9.2 and everything worked fine with object - void * - object conversion, but object - void * -

Re: Problem with casting instance reference to void* and back.

2015-07-27 Thread anonymous via Digitalmars-d-learn
On Monday, 27 July 2015 at 13:11:33 UTC, anonymous wrote: In the first example, you pass a pointer to a class instance. You cannot get the vtbl entry for the interface like this. Instead try to do this in 2 steps: actually i meant you pass an untyped pointer, so when you cast as interface

Re: Why hide a trusted function as safe?

2015-07-27 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/26/15 9:11 AM, Dicebot wrote: I remember doing something like that in druntime because of objects - you can't override @safe method prototype with @trusted one. But you can, at least now you can, maybe it's changed. In answer to the original question, the given code is quite

Re: Yes or No Options

2015-07-27 Thread Namespace via Digitalmars-d-learn
Look at my example: import std.stdio; import std.string; import std.conv : to; void main() { while (true) { write(Roll the dice: Enter a number: ); int dieNumber = readln.strip.to!int; if (dieNumber 4) { writeln(You won!); } else if

Yes or No Options

2015-07-27 Thread Alex via Digitalmars-d-learn
Hey guys! I am super new to programming and still trying to learn the very basics via a book that I bought. My problem is the following: import std.stdio; import std.string; void main() { char[] yesno; write(Roll the dice: Enter a number!); int dieNumber;

Re: Yes or No Options

2015-07-27 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 27 July 2015 at 15:50:11 UTC, Alex wrote: readf( %s, dieNumber); What happens here is a bit tricky and trips up a lot of programmers: readf leaves the end-of-line character in the buffer, which readln then sees as meaning its job is done. When you enter, say, 5, then

Re: Yes or No Options

2015-07-27 Thread Alex via Digitalmars-d-learn
On Monday, 27 July 2015 at 17:31:08 UTC, Ali Çehreli wrote: On 07/27/2015 08:50 AM, Alex wrote: a book that I bought The program looks a lot like one of the exercises in this chapter: http://ddili.org/ders/d.en/if.html You didn't actually pay for it, right? Because it is free. :) Ali

Re: Yes or No Options

2015-07-27 Thread Alex via Digitalmars-d-learn
Okay. By pure trying I found out what I did wrong: Apparently by typing Y I entered the shift key. Could that have been the problem? I changed it to a small y and it at least jumped back to the commandline instead of just being stuck. And by changing: writeln(Do you want to play again?

Re: Yes or No Options

2015-07-27 Thread Anonymous via Digitalmars-d-learn
On Monday, 27 July 2015 at 16:48:00 UTC, Alex wrote: Okay. By pure trying I found out what I did wrong: Apparently by typing Y I entered the shift key. Could that have been the problem? I changed it to a small y and it at least jumped back to the commandline instead of just being stuck. And

Re: Yes or No Options

2015-07-27 Thread Alex via Digitalmars-d-learn
Thank you! That helped me a lot. I'm sure that - in order to get to the point to repeat the whole first part of the program - I'll have to read further in the instructions I have BUT let's just say that I don't want it to repeat the first part of the program but just writeln something like

Re: Problem with casting instance reference to void* and back.

2015-07-27 Thread Vlad Leberstein via Digitalmars-d-learn
auto self = cast(TestInterface)cast(Object) rawSelf Works like a charm! Thank you both!

Re: Yes or No Options

2015-07-27 Thread CraigDillabaugh via Digitalmars-d-learn
On Monday, 27 July 2015 at 17:21:33 UTC, Anonymous wrote: On Monday, 27 July 2015 at 16:48:00 UTC, Alex wrote: Okay. By pure trying I found out what I did wrong: Apparently by typing Y I entered the shift key. Could that have been the problem? I changed it to a small y and it at least jumped

Re: Yes or No Options

2015-07-27 Thread Ali Çehreli via Digitalmars-d-learn
On 07/27/2015 08:50 AM, Alex wrote: a book that I bought The program looks a lot like one of the exercises in this chapter: http://ddili.org/ders/d.en/if.html You didn't actually pay for it, right? Because it is free. :) Ali

Re: Yes or No Options

2015-07-27 Thread Tofu Ninja via Digitalmars-d-learn
On Monday, 27 July 2015 at 16:48:00 UTC, Alex wrote: Okay. By pure trying I found out what I did wrong: Apparently by typing Y I entered the shift key. Could that have been the problem? I changed it to a small y and it at least jumped back to the commandline instead of just being stuck. And

Re: Where can i find examples of multi-threaded fibers?

2015-07-27 Thread Gary Willoughby via Digitalmars-d-learn
On Monday, 27 July 2015 at 08:00:10 UTC, Marc Schütz wrote: On Sunday, 26 July 2015 at 18:07:51 UTC, Gary Willoughby wrote: In the description for Fiber in std.thread is the following[1]: Please note that there is no requirement that a fiber be bound to one specific thread. Rather, fibers may

Can't Compile Global Semaphores?

2015-07-27 Thread Jack Stouffer via Digitalmars-d-learn
Hi, I am currently working through a book on the fundamentals of computer concurrency and I wanted to do all of the exercises in D. But I ran into a problem when I tried to have a global semaphore: /usr/local/Cellar/dmd/2.067.1/include/d2/core/sync/semaphore.di(35): Error: constructor

Re: Can't Compile Global Semaphores?

2015-07-27 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/27/15 3:10 PM, Jack Stouffer wrote: Hi, I am currently working through a book on the fundamentals of computer concurrency and I wanted to do all of the exercises in D. But I ran into a problem when I tried to have a global semaphore:

Re: Can't Compile Global Semaphores?

2015-07-27 Thread Ali Çehreli via Digitalmars-d-learn
On 07/27/2015 12:56 PM, Steven Schveighoffer wrote: Instead, do this: shared Semaphore sem; shared static this() { sem = new Semaphore(); } Which will run during runtime startup. Or, you can initialize in main(). -Steve I tried that as well but there are tons of issues with shared. :(

Re: Can't Compile Global Semaphores?

2015-07-27 Thread John Colvin via Digitalmars-d-learn
On Monday, 27 July 2015 at 19:56:15 UTC, Steven Schveighoffer wrote: On 7/27/15 3:10 PM, Jack Stouffer wrote: Hi, I am currently working through a book on the fundamentals of computer concurrency and I wanted to do all of the exercises in D. But I ran into a problem when I tried to have a

Re: Can't Compile Global Semaphores?

2015-07-27 Thread Jack Stouffer via Digitalmars-d-learn
On Monday, 27 July 2015 at 20:12:10 UTC, John Colvin wrote: Yes, but then core.sync.semaphore doesn't support being shared, so... Ok, so I made the code run by using __gshared instead of shared. It seems really odd that a semaphore object doesn't support being shared, this that a bug? Here

Re: GC stats

2015-07-27 Thread via Digitalmars-d-learn
On Sunday, 26 July 2015 at 17:43:42 UTC, Martin Nowak wrote: On 07/26/2015 04:16 PM, Gary Willoughby wrote: I thought there is a recently added compiler option that profiles the GC and creates a report now? That's an allocation profiler, the other one mentioned by me reports GC stats as

Why approxEqual not working for integers in dmd 2068-b2

2015-07-27 Thread lobo via Digitalmars-d-learn
Hi all, I have a bunch of unittests for template code taking any numeric type. Because I'm lazy I just use the approxEqual for both floating point and integer comparisons in these tests. In DMD 2067.1 everthing compiled OK but in 2068-b2 I get the errors shown at the end of this post for

Re: Where can i find examples of multi-threaded fibers?

2015-07-27 Thread via Digitalmars-d-learn
On Sunday, 26 July 2015 at 18:07:51 UTC, Gary Willoughby wrote: In the description for Fiber in std.thread is the following[1]: Please note that there is no requirement that a fiber be bound to one specific thread. Rather, fibers may be freely passed between threads so long as they are not