D Documentation [ Log in ]
A first program in D!
Fire up your favourite text editor! (There are a lots of text editors that support D or can be set up to handle D).
To do: A page with all the text editor support, link to it from here :)

Type (or copy-and-paste) the following code:
int main(char[][] args)
{
  return 0;
}

Save this file as "test.d" wherever you want to save your programming projects :)

You have to compile the program with DMD before you can execute it. For such small programs it is totally sufficient to write a batch file that compiles your program. (For larger programs you will use a build tool or Makefiles if you want to edit them a lot).
Just create a new text file named "test.bat" and type those two lines:
@dmd test.d
@pause >nul


The first line executes the D compiler, the second line will wait for you to press enter, so the window stays open and you can read the output of the compiler (The "@pause"). Save the file to the same directory as "test.d" and execute it. This is what my computer says:

C:\D\bin\link.exe test,,,user32+kernel32/noi;

This means the code was compiled successfully. You should now have some new files:
  • test.exe - your program in executable format
  • test.map - an auxilary file (can be viewed with a text editor)
  • test.obj - the compiled but not linked version of the program

You can safely delete any of these three files - the compiler will generate them again when you compile your program. Now you can run your test.exe - if you just double-click it a console window will be opened and almost immediately closed again because the program has already finished. (It's fast, isn't it? :)

If you want to see the output, just write another batch file "run-test".bat":
@test.exe
@pause>nul

(Almost the same thing as the test.bat)

When you double-click it you should see an empty window, when you press enter the window is closed.

Congratulations, you have written your first D program! It simply does nothing else than immediately exit after you start it, but it works - and it is fast :)
PHP docwiki written by Markus Dangl. Best viewed with Mozilla Firefox.
This is the inofficial wiki for documenting the D programming language.
- Profiler -
Time for site generation: 0.0179 s