Jump to page: 1 2
Thread overview
C standard libraries
Jul 01, 2013
CJS
Jul 01, 2013
Adam D. Ruppe
Jul 02, 2013
CJS
Jul 02, 2013
bearophile
Jul 02, 2013
Gary Willoughby
Jul 02, 2013
bearophile
Jul 02, 2013
Adam D. Ruppe
Jul 02, 2013
bearophile
Jul 09, 2013
Gary Willoughby
Jul 10, 2013
Timothee Cour
Jul 01, 2013
Jonathan M Davis
Jul 02, 2013
John Colvin
July 01, 2013
Is there some header/module that includes declaration for all C standard libraries?

I'm wondering both in general for future reference, and for the specific case of wanting to time a function and not knowing what in D--even after looking through the docs--would do something equivalent to clock and CLOCKS_PER_SEC in the C standard library time.h.
July 01, 2013
On Monday, 1 July 2013 at 16:32:32 UTC, CJS wrote:
> Is there some header/module that includes declaration for all C standard libraries?

It is in core.stdc. For example:

import core.stdc.stdio; // <stdio.h>
import core.stdc.stdlib;// <stdlib.h>

etc.

> what in D--even after looking through the docs--would do something equivalent to clock and CLOCKS_PER_SEC in the C standard library time.h.

import core.stdc.time;

import std.stdio; // for writeln
writeln(CLOCKS_PER_SEC);


The C headers in D aren't much documented, but they have all the same stuff as in C itself, so if you translate the include to import, the rest should continue to just work.


If you want to get to more OS specific stuff, outside the C standard but still typical C libs, it is core.sys.posix.unistd; /* <unistd.h> */ core.sys.windows.windows /* <windows.h> */ and so on.

The windows.h translation is *horribly* incomplete though, so if you want to do a serious win32 program you'll probably want to get something else. There's a win32 bindings somewhere on the net, if you need it I can find the link.
July 01, 2013
On Monday, July 01, 2013 18:32:30 CJS wrote:
> Is there some header/module that includes declaration for all C standard libraries?
> 
> I'm wondering both in general for future reference, and for the specific case of wanting to time a function and not knowing what in D--even after looking through the docs--would do something equivalent to clock and CLOCKS_PER_SEC in the C standard library time.h.

If you want to time a function, checkout std.datetime.StopWatch: http://dlang.org/phobos/std_datetime.html#StopWatch

As for C standard library functions in general, as Adam pointed out, they're in the in the core.stdc.* modules.

- Jonathan M Davis
July 02, 2013
> It is in core.stdc. For example:
>
> import core.stdc.stdio; // <stdio.h>
> import core.stdc.stdlib;// <stdlib.h>
>
> etc.
>

Thanks! I'm confused why that module isn't mentioned in the  library reference page.

What's the difference between core.stdc and std.c? The docs do refer to core.stdc, though std.c.stdio in Phobos' source just imports core.stdc.stdio. The duplication seems a bit weird, and I'm wondering if one method is deprecated or migth be removed in the future.

July 02, 2013
CJS:

> What's the difference between core.stdc and std.c? The docs do refer to core.stdc, though std.c.stdio in Phobos' source just imports core.stdc.stdio. The duplication seems a bit weird, and I'm wondering if one method is deprecated or migth be removed in the future.

Use core.stdc, and forget of std.c.

Bye,
bearophile
July 02, 2013
On Monday, 1 July 2013 at 18:09:32 UTC, Jonathan M Davis wrote:
> On Monday, July 01, 2013 18:32:30 CJS wrote:
>> Is there some header/module that includes declaration for all C
>> standard libraries?
>> 
>> I'm wondering both in general for future reference, and for the
>> specific case of wanting to time a function and not knowing what
>> in D--even after looking through the docs--would do something
>> equivalent to clock and CLOCKS_PER_SEC in the C standard library
>> time.h.
>
> If you want to time a function, checkout std.datetime.StopWatch:
> http://dlang.org/phobos/std_datetime.html#StopWatch
>

+1

I really came to hate c's clock, StopWatch has been much more pleasant experience to work with.
July 02, 2013
> Use core.stdc, and forget of std.c.
>
> Bye,
> bearophile

What's the reason for that?
July 02, 2013
Gary Willoughby:

> What's the reason for that?

Moving the C stuff in core is probably a way to remember D programmers that stuff is not normal stuff you are supposed to use in D programs. A D programmer should use the normal safer and nicer D functions. Core is there for special cases.

Bye,
bearophile
July 02, 2013
On Tuesday, 2 July 2013 at 06:33:03 UTC, CJS wrote:
> Thanks! I'm confused why that module isn't mentioned in the  library reference page.

I don't know.

> What's the difference between core.stdc and std.c?

std.c is what it was called in earlier versions of D, before there was a clear separation between phobos as the standard library (std.*) and druntime as the runtime library (core.*). Phobos is supposed to be 100% on top of druntime, so it is optional and interchangeable with ease.

The runtime, however, needed access to some C functions for its own implementation. Since it isn't allowed to depend on std.*, the C functions got moved into core.*.

The older std.c is kept around just for compatibility with the old names before the move, at least as far as I know. Maybe they haven't fully deprecated it though because there's other reasons I don't know about, since it has been many years now since the move.
July 02, 2013
Adam D. Ruppe:

> The older std.c is kept around just for compatibility with the old names before the move, at least as far as I know. Maybe they haven't fully deprecated it though because there's other reasons I don't know about, since it has been many years now since the move.

In D/Phobos/Dmd there is a ton of stuff that's supposed to be
obsolete, that should not be used, that is deprecated, etc. I
presume Walter thinks that the problems caused from keeping it
and from unwanted usages of it, is smaller than the breaking
troubles caused by removing it. I am person that likes to keeps
things ordered and clean, so I prefer to remove old stuff after a
suitable deprecation period, instead of keeping it around almost
forever (like floating point special comparison operators).

Bye,
bearophile
« First   ‹ Prev
1 2