How does calling function pointers work?

helxi brucewayneshit at gmail.com
Mon Nov 12 16:29:24 UTC 2018


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(?)


More information about the Digitalmars-d-learn mailing list