www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Necessity of D Library (and/or Core Library)

reply "Anthony Monterrosa" <AnthonyMonterrosa iCloud.com> writes:
     Does D require the standard library to function? Or to be 
more direct, does D as a language need its library, or core 
library, to function correctly?

     I have become very interested in how programming languages do 
their magic; how they interact with the computer itself, and 
their inner mechanics. This eventually led me to resources that 
said the line between a language and its library differs between 
languages, and I was wondering where D stood on that line.

     Note: since, I'm already here, does anyone know how D 
manipulates/uses standard streams to make its write/read 
functions as well? I can't find any resources telling me a 
non-abstracted way of this being completed.

P.S. I'm only a freshman computer science student, so if some of 
this should be basic, I simply don't know it yet.

Thanks in advance!
May 22 2015
next sibling parent Rikki Cattermole <alphaglosined gmail.com> writes:
On 23/05/2015 6:35 p.m., Anthony Monterrosa wrote:
      Does D require the standard library to function? Or to be more
 direct, does D as a language need its library, or core library, to
 function correctly?

      I have become very interested in how programming languages do their
 magic; how they interact with the computer itself, and their inner
 mechanics. This eventually led me to resources that said the line
 between a language and its library differs between languages, and I was
 wondering where D stood on that line.

      Note: since, I'm already here, does anyone know how D
 manipulates/uses standard streams to make its write/read functions as
 well? I can't find any resources telling me a non-abstracted way of this
 being completed.

 P.S. I'm only a freshman computer science student, so if some of this
 should be basic, I simply don't know it yet.

 Thanks in advance!
D can function without any form of standard library or runtime on e.g. embedded devices. But it will be next to useless without druntime. Druntime atleast in master requires libc. Libc defines things such as malloc and free. As well as other required functions to interact with the OS with. Although OS libs such as user32 on windows is used. It also provides the GC. But phobos itself is not required in any sense for D to work. It's just library code that comes with it.
May 23 2015
prev sibling next sibling parent "Kagamin" <spam here.lot> writes:
On Saturday, 23 May 2015 at 06:35:50 UTC, Anthony Monterrosa 
wrote:
     Does D require the standard library to function? Or to be 
 more direct, does D as a language need its library, or core 
 library, to function correctly?
Phobos is not required completely. D runtime can be a couple of lines not counting object.d. If you want all asserts, string switch and bounds checking (which I nice to have) and nice error reporting, it can grow to 100 lines or so.
     Note: since, I'm already here, does anyone know how D 
 manipulates/uses standard streams to make its write/read 
 functions as well? I can't find any resources telling me a 
 non-abstracted way of this being completed.
Phobos works on top of C stdio.
May 23 2015
prev sibling next sibling parent "lobo" <swamplobo gmail.com> writes:
On Saturday, 23 May 2015 at 06:35:50 UTC, Anthony Monterrosa 
wrote:
     Does D require the standard library to function? Or to be 
 more direct, does D as a language need its library, or core 
 library, to function correctly?

     I have become very interested in how programming languages 
 do their magic; how they interact with the computer itself, and 
 their inner mechanics. This eventually led me to resources that 
 said the line between a language and its library differs 
 between languages, and I was wondering where D stood on that 
 line.

     Note: since, I'm already here, does anyone know how D 
 manipulates/uses standard streams to make its write/read 
 functions as well? I can't find any resources telling me a 
 non-abstracted way of this being completed.

 P.S. I'm only a freshman computer science student, so if some 
 of this should be basic, I simply don't know it yet.

 Thanks in advance!
I have some bare metal code that works without Druntime. The compiler injects code that references some druntime components, which causes the linker to barf if they're not defined somewhere. You can simply define them as global void* vars like so: --- module kernel.kmain; // So we compile without druntime. extern(C) __gshared void* _d_dso_registry; extern(C) __gshared void* _Dmodule_ref; extern(C) __gshared void* _d_arraybounds; extern(C) __gshared void* _d_assert; extern(C) __gshared void* _d_unittest; // rest of code here --- This was back in DMD 2.065 so things may have changed between then and now. bye, lobo
May 23 2015
prev sibling parent reply "Mike" <none none.com> writes:
On Saturday, 23 May 2015 at 06:35:50 UTC, Anthony Monterrosa 
wrote:
     Does D require the standard library to function? Or to be 
 more direct, does D as a language need its library, or core 
 library, to function correctly?
There are two main libraries in D: The D Runtime, and the standard library (a.k.a. Phobos) By default, D links in Phobos and the D Runtime. With the GDC compiler, the two are actually compiled as a single binary. You can disable linking phobos and the D Runtime with the -nophoboslib compiler flag. I'm not sure if DMD or LDC offer a similar compiler option. You could, however, compile to object files and then link manually with the system linker to avoid linking in phobos and the D Runtime. If you don't explicitly import anything, then you won't need phobos, but you may need the D Runtime depending on which features of the language you use. However, if you stick to a C-like subset of D, you need very little of the D Runtime (50~100 lines of code)
     Note: since, I'm already here, does anyone know how D 
 manipulates/uses standard streams to make its write/read 
 functions as well? I can't find any resources telling me a 
 non-abstracted way of this being completed.
It is my understanding that D links in the C standard library and leverages the functionality there for standard streams. Mike
May 23 2015
parent "Adam D. Ruppe" <destructionator gmail.com> writes:
On Saturday, 23 May 2015 at 12:47:12 UTC, Mike wrote:
 You can disable linking phobos and the D Runtime with the 
 -nophoboslib compiler flag.  I'm not sure if DMD or LDC offer a 
 similar compiler option.
-defaultlib= You can use that to change to linking to a .so for example but leaving it blank means no phobos/druntime at all.
May 23 2015