Global extern(C) in druntime header files?

Gary Willoughby dev at kalekold.net
Wed Jun 5 11:04:20 PDT 2013


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?


More information about the Digitalmars-d-learn mailing list