Last update July 31, 2009

Faq Roadmap



Difference (previous author) (Change, Edit, normal page display)

Changed: 1c1
This page lists typical questions from D users. Most of them are simply recorded from NewsDmD without much reworking. There are of two other FAQs you might check:
This page lists typical questions from D users. Most of them are simply recorded from the newsgroups without much reworking. There are of two other FAQs you might check:

Changed: 3,4c3,4
* Official DigitalMars FAQ ( D 1.x, D 2.x) and the [DocComments/FAQ Comments page]
* D FAQ (at MKoD - D Programming Language)
* Official FAQ D 1.x, D 2.x (Alpha) DocComments/FAQ
* MKoD FAQ

Changed: 6c6
This page is intended to act an simple authoring system to prepare content for both or any other FAQ someone might want to create. You may add questions at the bottom of this page or ask in NewsDmD.
This page is intended to act an simple authoring system to prepare content for both or any other FAQ someone might want to create. Once the questions receive a more formalized response, they will be moved to an appropriate FAQ location:

Changed: 8c8,11
[[toc]]
* [[link]General Development[url= http://www.prowiki.org/wiki4d/wiki.cgi?DevelopmentWithD/FAQ]]
* [[link]DMD Complier[url= http://www.prowiki.org/wiki4d/wiki.cgi?D__Tutorial/StartingWithD/Compiler/DMD/FAQ]]
* [[link]Porting [url= http://www.prowiki.org/wiki4d/wiki.cgi?PortingOverview/FAQ]]
* Error Messages

Changed: 10c13


[[toc]]

Deleted: 12,170d14
== General questions =

=== Searching for information about D =

See SearchingTips

=== Licensing =

Which parts of the Digital Mars D implementation are Free software? [Apr 04]

The DMD front-end source is available under dual ( GPL and Artistic) license. Phobos, the D standard library, is now licensed under a zlib/libpng license unless the individual file specifies otherwise. The DMD compiler, back-end and libraries are licensed non-distributable under a DigitalMars license. The D language specification and accompanying documents are similarly copyrighted to DigitalMars. -- JustinCalvarese, additions by AndersFBjörklund

May anyone create their own D implementation (of course, following the D Specification), and call it "D"? [Apr 14]

Yes, in fact there have already been a few ports of the DMD source released: GDC and dli. The implementor should add a predefined version for the implementation and change std.compiler.name to reflect the new implementation. As far as I know, Walter has not mentioned any need for conformance testing requirements (such as with Sun's Java). Someone did suggest that we might want a "pureD" stamp of approval, but I'm pretty sure that wasn't Walter's idea.

Obviously if the implementor ignored the D Specification, the implementation wouldn't be very popular with the D community. I don't think Walter has any kind of trademark on the letter D, so I think we're basically on the honor system. -- JustinCalvarese


=== How stable is D =

How stable is it to use in a final product development? [January 07]

Obviously this is a difficult question to answer for a new language. DMD 1.0 has been released with the new year, marking a new important milestone for the language and the stabilisation of its specification. While D has a stable high performance compiler and a lot of people see a bright (no pun intended) future, there is still a lot to be done.

In short, at the moment D works very well (even though it does not have the stability of older languages). What needs to be worked on the most now is probably around libs and IDEs. There are not that many D libs (bindings or not) and IDEs around at the moment, and most of them are still alpha or beta.

So, my opinion is that D is now an awesome language, but you still need to feel a bit ready for involvement in making the community grow and the language spread. A casual programmer that just wants a tried-and-proved solution to make an app in a productive environment should perhaps wait a little bit more.

(my opinion about DMD 0.73 in Oct03) A cautious programmer like me uses D for tool development but not yet for final product development. I expect to do final product development in 2004. -- HelmutLeitner


=== How to become more involved =

I'm really interested in D and want to become more involved in the community. Does anyone have any suggestions on how I can become more involved in the development and growth of this language and community? [adapted from a newsgroup question Mai 04]

# How about visiting http://www.dsource.org and check out the projects there. Pick one and contact the admin of the project to see how you can help. Check the forums to see how development is progressing. [Brad Anderson]

# You could contribute to Wiki4D, for any finding, any question, any single piece of information is useful and paves the path... [HelmutLeitner]

# Assuming you want to learn by getting your hands dirty: I would love to have a command-line tool, called resub, that effects regular expression substitution on text input - whether typed in or more usually piped from stdin - on a line-by-line basis. This would use the std.regexp and std.stream modules, and would give you a good grounding in D. [Matthew] Isn't there already program called sed that does exactly this?


== Programming in D =


=== Libraries =

Are there libraries for D?

Various libraries are listed on the Libraries page (also see Standard Libraries, GUI Libraries, and Database Bindings).


=== Call methods in parent class =

Is there a way to call methods in a parent class? Even if the child class overloads the method definition? [Benji Smith, Aug 03]

Yes, use super.method( .... ); [Mike Winn]


=== How to sort an array of struct =

How can I sort an array of struct without writing my own sorting routine?

You have to provide a <n>{TypeInfo }?*</n> class corresponding to the struct. Example: HelmutLeitner/StructSort.

This has changed since DMD 0.110. (Apparently, struct arrays are sorted based on the first element of the struct.)


=== How to convert to void[] =

What is the best way to convert a struct to a void[]?

You can do:
Foo f;
void[] fv = (cast(void*)&f)[0..f.sizeof];
and even:
void[] fv = (&f)[0..1];
works, because any array implicitly converts to void[].



== Compiler questions =

=== -release flag =

The dmd compiler has several flags for controlling whether optimizing or debugging features are activated. I think I understand -g -O -debug and -version, but I'm unclear what the -release flag does.

-release eliminates assertion tests explicit:
assert (x);
and implicit:
// if -release is not given, this checks that y is in bounds for x.
x [y] = z;
-release essentially turns all runtime safety controls off. I don't
recommend it - if your program goes bad, it'll be very difficult to find
out where and why. Array-using code is impacted by the checks, but you
can get around that safely in inner loops by using pointers. [Burton Radon, Sep04]



== Windows related questions =

=== How to call a Windows API function ===

I am trying to call the <n>OutputDebugString?</n>() function and can't quite figure out how to make this work.

The windows.d module is not yet complete. Declare the function you want to use:

[[Code]
extern (Windows) void OutputDebugStringA? (char*);
]

and add kernel32.lib to your linker command.

=== How to suppress the console window with a Windows application ===

How do I get rid of that dumb console widow that appears with my application?

There are at least 3 ways to keep the console window from appearing.
* Add -L/EXET:NT -L/SU:windows to the command line (Charles Sanders, NG:D/20386):
[[Code]dmd -L/EXET:NT -L/SU:windows myWinApp.d]
* Or create a .def file like the following and add the .def file to the command line:
[[Code]EXETYPE NT
SUBSYSTEM WINDOWS]
[[Code]dmd myDef.def myWinApp.d]
* If you're using [DsourceProjects?:build Bud] to compile your application, an easier way is to add the following to bud's command line:
[[Code]-gui:4.0]
(The version number 4.0 specifies that the application should be allowed to run on Windows 95 or above. Leaving off the version number will cause your operating system to be chosen as the minimum allowed Windows version, which might be bad.)


=== How to reserve space in a dynamic array =

I'm filling a dynamic array, but I don't know how big it will be. What's the most efficient way fill this array? (Changing the size each time is clearly inefficient.)

After setting .length to the max reasonable size, then set .length back to
one. You now have a reserve that is something like the max reasonable size
rounded up to the next bucket size (WalterBright, NG:D/17688 with change by Ben Hinkle to say to avoid setting the length to zero since that nulls out the data pointer).

=== Why is alias used instead of typedef in Windows headers? =

I noticed that in std.c.windows.windows the types are all defined as aliases. Would it be better from a type safety and potential overloading point-of-view to use typedefs? ( NG:D/27759)

One of my early thoughts was also to clean up the win32 type system. Unfortunately, most code plays fast and loose with using C typedefs mixed in with the underlying types. Microsoft's own sample code is woefully inconsistent about it. It's so much easier to just use alias for them and not worry about it. Save the clean designs for doing something new, not legacy API's. (from NG:D/15278 by WalterBright)

=== How to create a Windows DLL =

Is it possible to make a .dll, or any other type of D shared library (Windows)?

See the example in \dmd\samples\d\mydll. [WalterBright, August 18, 2004]

== Converting from C =

=== Central header file =

I typically use a single central header file in my C projects (which contains a lot of includes), that is included by all source files of the project with a single command. How can I do this in D without having a "#include"?

Use a module instead of a header. Put all your import statements there (and make them public imports). Import this module.

Also try to distribute your declarations to the modules that they belong in, reducing the size of your import module. --Ameer Armaly

Deleted: 220,354d63


== Advanced D =

=== Running a debugger =

Which debuggers can use the debugging information generated by the compiler?

Any debugger that uses standard debugging information. If using linux, you
can use gdb. If using Windows, you can use, for example, Microsoft's
windbg.exe program (which comes on the DMC++ CD). -- WalterBright, NG:D/22036

You can also use OpenWatcom Debugger to debug the Code
generated by DMD (and DMC).
Before loading the program in the memory, you need to add your source path to
the debugger.

See Debug Environments for more information.


=== Does D support boolean types? ===

Yes, a real bool type was added to the language.

See: http://digitalmars.com/d/type.html (scroll down to "bool")


=== Does D support any form of RTTI? =

Does D support any form of RTTI? I didn't see any mention of this on the webpage.

There's some support for it already. For any object you can always get a <n>ClassInfo?</n> structure and see the name of the class, which class is its parent and which interfaces it implements:

[[Code]
import stream;

File f = File();
ClassInfo? fci = f.classinfo;

printf("Class name: %s\n", fci.name);
printf("Base class name: %s\n", fci.base.name);
]

There's a pointer to the vtable, contructors, destructor and invariant methods. You can see the <n>ClassInfo?</n> source in /dmd/src/phobos/object.d. [Julio César Carrascal Urquijo]

See also: How to... RTTI


=== What are imaginary types good for? =

I don't understand what the imaginary types (ifloat, idouble and ireal) are for. Can you explain?

Having a separate imaginary type is necessary for some complex arithmetic calculations that need to preserve the sign of branch cuts. Multiplying by an imaginary number doesn't have quite the same semantics as multiplying by 0+yi. Hopefully, this will explain it better than I can:

http://www.cs.berkeley.edu/~wkahan/JAVAhurt.pdf

A branch cut (simplisticly) is attempting to draw a distinction between +0 and -0. It comes up a lot in complex arithmetic calculations. Prof. Kahan did another paper on that, but unfortunately it isn't online. [Walter Bright]


=== Conversion delegate <=> function pointer =

Is there a way to convert a delegate to a function pointer (or the other way round)? [HelmutLeitner, Apr 2003]

Currently, no. There will be in the future, though. [WalterBright]

See also: Delegate Hack, NG:D/12571, NG:D/26318


=== <n>Self-Compiling?</n> Compiler =

Will DMD ever be converting into a self-compiling compiler?

Maybe someday in the future. D is certainly powerful enough to write a D compiler.

In the meantime, many other issues have a higher priority. (Part of the challenge to convert the current C++ sources to D is that the interface to his backend isn't trivial. There are a number of .h files, the back end is in C++, and it would be a fair chunk of work to interface it.)

Walter has far too many other things to do right now.

Adapted from NG:digitalmars.D:19899 and NG:digitalmars.D:19929.



== Implementation detail =


=== Virtual function table pointer =

If there are no virtual functions left in a class, does the VFT pointer go away? [Bill Cox, Jan 03]

No, it's always there, both because it inherits from Object which has virtual functions, and because many features rely on the first entry in the VFT being a pointer to the <n>ClassInfo?</n>. [Walter Bright]



== Supported Platforms =


=== D front end for GCC =

Is anybody working on a front end for GCC?

David Friedman has been working on a D front end for GCC called GDC.

According to his website (2006/06/07):

GDC works with GCC versions 3.3.x, 3.4.x, 4.0.x, 4.1.x, and 4.2.x.
Supported Systems
* Linux (tested on Fedora Core 5 x86 and PowerPC)
* Mac OS X 10.3.x, 10.4.x
* <n>FreeBSD 5.2.1</n>
* Cygwin
* <n>MinGW?</n>
* AIX (tested on 5.1)
* <n>SkyOS?</n> (incomplete)

Similar versions should work and other Unix platforms may work. Although the compiler will probably work on most 32-bit architectures, the D runtime library will still need to be updated to support them.


=== D compiler for Solaris =

Does somebody have any information about D compiler for Solaris OS? Is it in the D evolution plan? [Gennadi Pais, Aug 03]

The D plan is to be available on all platforms 32 bits and larger. But getting on Solaris would require someone to take the lead on doing it. [Walter Bright]

Marcel Martin wrote a patch to GDC for Sun Solaris support ( NG:D.gnu/1025).



== D website owners =


=== Use of Digital Mars D logos =

May I use the Digital Mars logo on my D project website? (I guess so, I've seen it on other sites) [Aug 03]

Yes, if it forms the link to Digital Mars! You can also use the images at the bottom of DigitalMars:d/dlinks.html [Walter Bright]


This page lists typical questions from D users. Most of them are simply recorded from the newsgroups without much reworking. There are of two other FAQs you might check:

This page is intended to act an simple authoring system to prepare content for both or any other FAQ someone might want to create. Once the questions receive a more formalized response, they will be moved to an appropriate FAQ location:

Table of contents of this page
Error Messages   
What does a particular error message mean?   
"Error: Access Violation" on printing a string   
Have another question?   

Error Messages    

What does a particular error message mean?    

If it's a common error, it may already be on the Error Messages list.

"Error: Access Violation" on printing a string    

You'll likely get an access violation if you try to print a char[] in this fashion:

printf("%s\n", input);

Use std.stdio.writef instead of printf, and std.stdio.writefln to print an extra newline after your output.

If you must use printf, this would be a correct way to do it:

printf("%.*s\n", input);

In D, arrays store their length, so character arrays need no terminating zero. In printf, the '%s' indicates a zero terminated string, so it fails when given a normal D string. The '%.*s' tells printf to expect a string preceded by its length. However, printf is still a C function, and so if the string contains embedded zero characters, printf will stop printing the string even before the specified length is reached. In other words, the '%.*s' will print until the length of the string is reached, or a zero is reached, whichever happens first.

The following examples will also work (though less efficient, because a temporary zero terminated string object is constructed):

printf(cast(char*) (input ~ "\n\0"));
printf(cast(char*) (input ~ \n ~ \0));
printf("%s\n",(char *)(input ~ \0));
printf("%s\n",(char *)input.dup);

Sometimes this is seen:

printf("%s\n",(char *)input);

but it is not always reliable, e.g. after:

char [] a="abcdefghij";
char [] input=a[3..4];
printf("%s\n",(char *)input);

it will not print "de" but "defghij" because no ending \0 is provided by the slice.

There is a HowTo/printf page giving more information on using printf.

Have another question?    

The best way to get an answer to another question is to post it in one of the D newsgroups.

FrontPage | News | TestPage | MessageBoard | Search | Contributors | Folders | Index | Help | Preferences | Edit

Edit text of this page (date of last change: July 31, 2009 18:58 (diff))