.d

What is a .d file?

D Source File · Code and data · Walter Bright / D Language Foundation · 2001

A .d file is D source code, a compiled systems language designed as a cleaner successor to C++. It combines native speed with garbage collection, modules and strong metaprogramming.

Category
Code and data
MIME type
Type
Plain text
Also seen as
.di
Is a .d file safe to open? Caution. A .d file is program source. Compiling and running it executes its code; review unfamiliar files first.

What is a .d file used for?

D was created by Walter Bright, author of the first native C++ compiler, to keep C++'s power while shedding its historical baggage: it adds modules, ranges, contracts and compile-time function execution.

One naming trap: build tools like Make also produce .d dependency files, which are small text lists, not D programs. A real D source file contains code with import statements and C-style braces.

How to open a .d file

The .d format opens in the following apps, grouped by operating system. If one app does not work, try another from the same list. For a step-by-step walkthrough, see how to open a .d file.

Windows

  • VS Code (code-d)
  • any text editor

macOS

  • VS Code (code-d)
  • any text editor

Linux

  • VS Code (code-d)
  • any text editor

How to convert a .d file

You can convert a .d file to exe (compiled) using a conversion tool or the export menu of an app that opens it.

.d file signature (magic bytes)

Programs recognise a .d file by the bytes at the start of the file, not by its name. These are the signatures for D.

Hex signatureOffsetNote
(no fixed signature)0plain text; no fixed magic bytes

See the full magic-numbers reference for every format.

Frequently asked questions

What is a .d file?

A .d file is D source code, a compiled systems language designed as a cleaner successor to C++. It combines native speed with garbage collection, modules and strong metaprogramming.

How do I run a .d file?

Install a D compiler (dmd, ldc or gdc) and run dmd -run file.d, or manage a project with dub, D's package and build tool.

Is every .d file a D program?

No. Compilers and Make generate .d dependency files, which are plain lists of file paths. If the content is code with imports and braces, it is D source.

How does D compare to C++?

D compiles to native code like C++ but adds garbage collection (optional), a module system and simpler metaprogramming, at the cost of a much smaller ecosystem.

Related formats

Sources

Details on this page were checked against authoritative references: