Search code examples
d

Cannot compile some simple D code


I'm compiling some simple code:

import std.c.time;
.
.
.
timespec zero;
nanosleep(&zero, null);
.
.
.

What I get is:

Error: undefined identifier timespec
Error: undefined identifier nanosleep

std.c.time is merely a shortcut to C's time.h. If I call other functions defined in time.h, say clock(), it's Ok. If I write analogous code in C (with nanosleep()), it's Ok. In time.h I see that timespec and nanosleep declarations are put under some #ifdef, possibly it has something to do with my problem ?

How can I get it to compile ?

My working environment is: dmd v2.059 Ubuntu 12.04


Solution

  • As nightcracker right pointed out, nanosleep() does not belong to C99 standard, however it belongs to POSIX, consequently, all that was needed is import core.sys.posix.time;. One general conclusion, search D libraries / interfaces.