D programming Language



Download 1.66 Mb.
Page1/47
Date08.01.2017
Size1.66 Mb.
#7507
  1   2   3   4   5   6   7   8   9   ...   47




D Programming Language


This Document is a unofficial snapshot of the official online documents at


http://digitalmars.com/d/index.html
and was created and posted with permission of Walter Bright. We hope that it will be useful for offline reading, even if there is no guarantee that this document is always up-to-date.
Revision history:

April 15, 2003: First compilation by Alexander Klinsky


Corrections and suggestions to:

news://news.digitalmars.com/D
© Digital Mars, 2003

created April 18, 2003, corresponding to DMD 0.61




"It seems to me that most of the "new" programming languages fall into one of two categories: Those from academia with radical new paradigms and those from large corporations with a focus on RAD and the web. Maybe its time for a new language born out of practical experience implementing compilers." -- Michael

"Great, just what I need.. another D in programming." -- Segfault

This is the reference document for the D programming language. D was conceived in December 1999 by myself as a successor to C and C++, and has grown and evolved with helpful suggestions and critiques by my friends and colleagues. I've been told the usual, that there's no chance for a new programming language, that who do I think I am designing a language, etc. Take a look at the document and decide for yourself!

The D newsgroup in news.digitalmars.com server is where discussions of this should go. Suggestions, criticism, kudos, flames, etc., are all welcome there.

Note: all D users agree that by downloading and using D, or reading the D specs, they will explicitly identify any claims to intellectual property rights with a copyright or patent notice in any posted or emailed feedback sent to Digital Mars.

-Walter


Table of Content

D Programming Language 1

What is D? 7

Why D? 7

Major Features of D 11

Sample D Program (sieve.d) 17

Lexical 19

Modules 29

Static Construction and Destruction 31

Declarations 32

Types 35


Basic Data Types 35

Derived Data Types 35

User Defined Types 36

Pointer Conversions 36

Implicit Conversions 36

Delegates 37

Properties 38

Properties for Integral Data Types 38

Properties for Floating Point Types 38

.init Property 38

Attributes 40

Linkage Attribute 41

Align Attribute 41

Deprecated Attribute 42

Protection Attribute 42

Const Attribute 42

Override Attribute 42

Static Attribute 43

Auto Attribute 43

Expressions 45

Evaluation Order 47

Expressions 47

Assign Expressions 47

Conditional Expressions 48

OrOr Expressions 48

AndAnd Expressions 48

Bitwise Expressions 49

Equality Expressions 49

Identity Expressions 49

Relational Expressions 50

Shift Expressions 52

Add Expressions 53

Mul Expressions 53

Unary Expressions 53

Postfix Expressions 55

Primary Expressions 55

Statements 57

Labelled Statements 58

Block Statement 58

Expression Statement 59

Declaration Statement 59

If Statement 59

While Statement 59

Do-While Statement 60

For Statement 60

Switch Statement 61

Continue Statement 62

Break Statement 62

Return Statement 63

Goto Statement 63

With Statement 63

Synchronize Statement 64

Try Statement 64

Throw Statement 65

Volatile Statement 65

Asm Statement 65

Arrays 67

Array Declarations 67

Usage 68

Slicing 68

Array Copying 69

Array Setting 69

Array Concatenation 69

Array Operations 70

Rectangular Arrays 71

Array Properties 71

Array Bounds Checking 73

Array Initialization 73

Special Array Types 74

Associative Arrays 75

Structs, Unions, Enums 78

Structs, Unions 78

Enums 78

Classes 81

Interfaces 88

Functions 92

Nested Functions 93

Operator Overloading 98

Unary Operator Overloading 98

Binary Operator Overloading 98

Future Directions 101

Templates 102

Instantiation Scope 103

Argument Deduction 104

Value Parameters 105

Specialization 105

Limitations 105

Contracts 106

Assert Contract 106

Pre and Post Contracts 106

In, Out and Inheritance 108

Class Invariants 108

Debug and Version 109

Predefined Versions 109

Specification 110

Debug Statement 110

Version Statement 111

Debug Attribute 111

Version Attribute 112

Error Handling in D 114

The Error Handling Problem 114

The D Error Handling Solution 115

Garbage Collection 117

How Garbage Collection Works 118

Interfacing Garbage Collected Objects With Foreign Code 118

Pointers and the Garbage Collector 118

Working with the Garbage Collector 119

Memory Management 120

Strings (and Array) Copy-on-Write 120

Real Time 121

Smooth Operation 121

Free Lists 121

Reference Counting 122

Explicit Class Instance Allocation 122

Mark/Release 124

RAII (Resource Acquisition Is Initialization) 125

Allocating Class Instances On The Stack 125

Floating Point 126

D x86 Inline Assembler 128

Labels 128

align IntegerExpression 128

even 129


naked 129

db, ds, di, dl, df, dd, de 129

Opcodes 129

Operands 130

Opcodes Supported 132

Interfacing to C 137

Calling C Functions 137

Storage Allocation 138

Data Type Compatibility 138

Calling printf() 139

Structs and Unions 139

Interfacing to C++ 140

Portability Guide 141

OS Specific Code 141

Embedding D in HTML 142

D Runtime Model 143

Phobos 145

D Runtime Library 145

Philosophy 145

Imports 145

compiler 147

conv 147


ctype 147

date 148


file 149

gc 149


intrinsic 150

math 152


object 155

outbuffer 155

path 156

process 157

random 157

regexp 157

stdint 159

stream 160

string 164

system 166

thread 166

zip 167


stdio 167

D for Win32 168

Calling Conventions 168

Windows Executables 168

DLLs (Dynamic Link Libraries) 169

COM Programming 171

D vs Other Languages 172

Notes 174

Programming in D for C Programmers 175

Programming in D for C++ Programmers 194

The C Preprocessor Versus D 202

The D Style 209

Example: wc 211

Compiler for D Programming Language 213

Files 213

Requirements 213

Installation 213

Example 213

Compiler Arguments and Switches 213

Linking 214

Environment Variables 215

SC.INI Initialization File 215

Bugs 215

Feedback 215

Acknowledgements 216

INDEX 217



Overview


Download 1.66 Mb.

Share with your friends:
  1   2   3   4   5   6   7   8   9   ...   47




The database is protected by copyright ©ininet.org 2024
send message

    Main page