How does calling function pointers work?
Alex
sascha.orlov at gmail.com
Mon Nov 12 16:53:01 UTC 2018
On Monday, 12 November 2018 at 16:29:24 UTC, helxi wrote:
> On Monday, 12 November 2018 at 16:25:13 UTC, Rene Zwanenburg
> wrote:
>> Idk where you got that syntax from, but there's no syntactic
>> difference between calling normal functions and function
>> pointers:
>
> import std.stdio;
> import std.concurrency;
> import core.thread;
>
> void worker(int firstNumber) {
> foreach (i; 0 .. 4) {
> Thread.sleep(500.msecs);
> writeln(firstNumber + i);
> }
> }
>
> void main() {
> foreach (i; 1 .. 3) {
> spawn(&worker, i * 10);
> }
> }
>
>
> Looks like worker needs an int and spawn(&worker, i * 10) seems
> to feed it's second arg to worker(?)
Yes, seems so. Accordingly to
https://dlang.org/library/std/concurrency/spawn.html
However, there are more restrictions on input params in the notes
section.
More information about the Digitalmars-d-learn
mailing list