Looking for documentation of D's lower-level aspects.

Sean Silva chisophugis at gmail.com
Mon Oct 17 22:08:33 PDT 2011


I have just finished reading Alexandrescu's The D Programming Language, but it
doesn't seem to talk at all about how to use D as a stand-in for C/C++ almost at
all. E.g., the part of D that doesn't depend on a runtime or garbage collector.

It's not that I have anything against those niceties---it all has its place;
it's just that I would like to learn how to use D as a replacement for C/C++,
rather than as a replacement for Java/C# (I have no interest in the kind of
programming that's done in Java/C#, so there's nothing to replace). I really
like having the safe D subset though, since it allows awesomeness to happen at
compile-time (this is one of my favorite things about D, actually).

As an example of the lack of coverage in this area, I just found this line in
the source code of SList in std.container:

     ahead = n._next;

<https://github.com/D-Programming-
Language/phobos/blob/master/std/container.d#L895>

The C/C++ equivalent of this is `ahead = n->next;`, or equivalently `ahead =
(*n).next;`. This is a difference in semantics from C/C++ with respect to the
`.`---it seems like D turns pointer to struct property accesses into property
access with indirection. Nowhere that I can recall in Alexandrescu's book talked
about this, but it's a really big deal!

Can I get some pointers (no pun intended) to resources about how to use D in
this role? I'm primarily interested in writing optimal (i.e. equivalent to hand-
coded C) generic data structures (like STL, for instance), and this entails
knowing how to use D at the lowest (well, just above asm) level. I'm sure that D
has a means to do this, almost surely better than C++, but I can't seem to find
any documentation about how to go about it.


More information about the Digitalmars-d-learn mailing list