www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - C standard libraries

reply "CJS" <Prometheus85 hotmail.com> writes:
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.
Jul 01 2013
next sibling parent reply "Adam D. Ruppe" <destructionator gmail.com> writes:
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.
Jul 01 2013
parent reply "CJS" <Prometheus85 hotmail.com> writes:
 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.
Jul 01 2013
next sibling parent reply "bearophile" <bearophileHUGS lycos.com> writes:
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
Jul 01 2013
parent reply "Gary Willoughby" <dev kalekold.net> writes:
 Use core.stdc, and forget of std.c.

 Bye,
 bearophile
What's the reason for that?
Jul 02 2013
parent "bearophile" <bearophileHUGS lycos.com> writes:
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
Jul 02 2013
prev sibling parent reply "Adam D. Ruppe" <destructionator gmail.com> writes:
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.
Jul 02 2013
parent reply "bearophile" <bearophileHUGS lycos.com> writes:
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
Jul 02 2013
next sibling parent "Gary Willoughby" <dev kalekold.net> writes:
On Tuesday, 2 July 2013 at 12:52:49 UTC, bearophile wrote:
 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
I agree. Also the website needs updating to deter people from using std.c: http://dlang.org/phobos/#stdio
Jul 09 2013
prev sibling parent Timothee Cour <thelastmammoth gmail.com> writes:
On Tue, Jul 2, 2013 at 5:52 AM, bearophile <bearophileHUGS lycos.com> wrote:

 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
at the very least it should go in http://dlang.org/deprecate.html even if there's no timeline for deprecation (or even if it will never be deprecated) This should be the ONE destination to find out deprecated stuff or discouraged stuff.
Jul 10 2013
prev sibling parent reply "Jonathan M Davis" <jmdavisProg gmx.com> writes:
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
Jul 01 2013
parent "John Colvin" <john.loughran.colvin gmail.com> writes:
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.
Jul 02 2013