I've been doing some coding and noticed something strange with core.sys.posix.signal. In the following snippet you will see that i have to decorate the handleTermination function with extern(C) to satisfy the type requirements of the bsd_signal function.

import core.sys.posix.signal;
import std.c.stdlib;
import std.stdio;

void main(string[] args)
{
        bsd_signal(SIGINT, &handleTermination);

        while (true)
        {
                
        }
}

extern(C) void handleTermination(int signal)
{
        writefln("Caught signal: %s", signal);
        exit(signal);
}

This seems really odd until you take a look at the header file. In signal.d you will see extern(C): specified at the top and then further down this:

   private alias void function(int) sigfn_t;

essentially decorating this alias with extern(C).

Is this right? Should this alias be decorated like that in the header file?

Reply via email to