XCODX |

D Online Compiler & Interpreter

Select Language
Online Code Compiler
Full HTML IDE
Py main.py
Program Output Ready
  Welcome to XCODX Online Compiler

  Quick Start:
  Ctrl+Enter  Run code
  Ctrl+S      Save / Download
  Ctrl+L      Clear output

  Select a language and start coding.
Success
Operation completed

About D

D is a compiled systems programming language created by Walter Bright at Digital Mars and first released in 2001, conceived as a redesign of C++ that keeps the performance while shedding much of the complexity. It is multi-paradigm — you can write imperative, object-oriented, functional, and heavily template-based code — and it compiles straight to fast native machine code. Its standard library is called Phobos, and modules such as `std.stdio` and `std.algorithm` cover everyday tasks. D also offers optional garbage collection alongside manual memory control, so you can pick the model that fits the job. On XCODX your source is compiled and run directly, giving you Phobos and the core language to experiment with in the browser.

Hello World in D

import std.stdio;
import std.string : strip;

void main()
{
    write("Enter your name: ");
    string name = readln().strip();
    writeln("Hello, ", name, "!");
    foreach (i; 1 .. 6)
        writeln(i, " squared is ", i * i);
}

When to use D

D works well when you want C++-level speed with a friendlier, more productive language — high-performance backends, numerical and systems code, and command-line tools are natural fits, and its ranges and templates make data-processing pipelines expressive. Choose it when you value both compile-time metaprogramming and the option of garbage collection. It reads familiarly to C, C++, and Java programmers, which eases the learning curve. It is less suited to settings that forbid any runtime or to teams needing the very largest package ecosystem, and here the Dub package manager is unavailable, so only Phobos is importable.

Common questions

Can I use Dub to install packages in this D compiler?

No. The sandbox exposes only the Phobos standard library — there is no Dub, no network access, and no persistent filesystem, so external packages cannot be downloaded. Your imports have to resolve to `std.*` or the core modules that ship with the compiler.

How do I read a line from stdin in D?

Use `readln()` from `std.stdio`, which returns the line including its trailing newline, so it is common to call `.strip()` (from `std.string`) to trim it. In the live terminal the program pauses at `readln` until you type and press Enter, or you can pipe input through the Stdin Box; Ctrl+D signals end of input. For formatted reads there is also `readf`.

Does D have a garbage collector?

Yes, D includes an optional garbage collector by default, but you are not forced to lean on it — you can use manual allocation, `@nogc` code, or scoped destruction when you need deterministic control. This dual model is one reason D spans both application and systems programming.

Is D the same as C or C++?

No, though it borrows their curly-brace style and much of their performance. D adds modules, optional garbage collection, built-in slices and arrays, cleaner templates, and compile-time function execution, while dropping the C preprocessor. A good deal of C code can be translated to D with modest changes.

Which D compiler and version does XCODX use?

The runtime badge shows the exact version; the sandbox typically runs a recent D 2.x compiler. You cannot switch compilers or pin a different release here.

Why can't my D program save files that persist?

Each run happens in a fresh, isolated environment with no persistent disk and no network, so files you create do not survive between runs and remote resources are unreachable. Use stdin and stdout for input and output within a single execution.

How D runs on XCODX

Sandbox filename
main.d
Entry point
single main source file
Editor grammar
d
Reading stdin
readln()
Input delivery
live WebSocket stream
Prompt flushing
flush manually before reading input
Compile limit
10 s
Run limit
3 s batch · up to 3 min live
Memory
256 MB per stage
Max source
50,000 characters

Default program on this page

import std.stdio;
void main() {
    writeln("Hello from D!");
    writeln("Welcome to XCODX Online Compiler!");
    string message = "D is awesome!";
    writeln(message);
}