Development With D /
FAQ
Other FAQS:
- Official FAQ D 1.x, D 2.x (Alpha) DocComments/FAQ
- MKoD FAQ
- StackOverflow, D related
- DMD Complier
- Porting
- Error Messages
- Shared
General questions
Searching for information about D
See Searching Tips
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 Boost 1.0 license unless the individual file specifies otherwise. The DMD compiler, back-end and libraries are licensed non-distributable under a DigitalMars license, but the source is available and comes with compiler. The D language specification and accompanying documents are similarly copyrighted to DigitalMars.
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
May I use the Digital Mars logo on my D project website? [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]
How stable is D
How stable is it to use in a final product development?
The D 1.x specification was finalized in 2007 allowing only for bug fixes in DMD or compiler features that did not change the specification. Its maintainance is scheduled to stop by the end of 2012.
D 2.x is the current main branch. Although its specification is mostly stable, it is a constantly evolving language. Most of the changes appear in the standard library, not in the core language. The languages changes may be additions, but great care is taken so that they are not breaking. Due to the newly available source, the DMD compiler has been receiving a great number of patches for bugs found in Bugzilla. A set of thousands of unit tests ensure that regressions are not introduced in new releases. A new release is usually scheduled every month.
Self-Compiling Compiler
A D compiler can be written in D. Work has been started on creating a D compiler in D, but nothing has been finished; check out the compiler page for an progress on this. As for DMD, this will not be converted since there are more important things to work on and you can't get a D compiler on new architectures without using a compiler for that architecture.
Programming in D
Call methods in parent class
Methods of a parent class can be called by using super.method(). You can also call the parents constructor using super() within a child class constructor. View the specification on constructors for more information.
Sort an array of struct
An array of struct is sorted by the first element in the structure. You can however customize this by providing a TypeInfo_* class corresponding to the struct. Example: HelmutLeitner/StructSort.
Convert struct to 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[].
Reserve space in a dynamic array and keeping the element count
Create a dynamic array to the max reasonable size, then set .length to your desired initial size. The size must be greater than zero as this will cause the array pointer to be null. If you want to grow the buffer again, you will need to keep a separate value for the reserved size.
Does D support any form of RTTI?
There's some support for it already. For any object you can always get a ClassInfo structure and see the name of the class, which class is its parent and which interfaces it implements:
|
There's a pointer to the vtable, contructors, destructor and invariant methods. You can see the ClassInfo source in /dmd/src/phobos/object.d. [Julio César Carrascal Urquijo]
See also: How to... RTTI
What are imaginary types good for?
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 (simplistically) 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
At this time the language does not provide any conversion between delegates and functions. This is supposedly planned but will only happen for D3.x or later. Functions can easily be rapped into a delegate and a function pointer can be obtained from a delegate.See also: Delegate Hack, NG:D/12571, NG:D/26318
Windows related questions
How to call a Windows API function
The windows.d module is not yet complete. Declare the function you want to use:
|
and add kernel32.lib to your linker command.
How to suppress the console window with a Windows 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):
|
- Or create a .def file like the following and add the .def file to the command line:
|
|
- If you're using Bud to compile your application, an easier way is to add the following to bud's command line:
|
Why is alias used instead of typedef in Windows headers?
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
Check out the page for writing DLLs.