学习D语言之helloworld

http://www.digitalmars.com/d/download.html下载dmd.zip(D compiler) for Win32 and Linux和dmc.zip (linker and utilities) for Win32
同一目录下解压dmd.zip和dmc.zip,将dmd\bin和dm\bin加入到path中
看看dmd\samples\d下的例子,如hello.d:
int main(char[][] args)
{
    printf("hello world\n");
    printf("args.length = %d\n", args.length);
    for (int i = 0; i < args.length; i++)
	printf("args[%d] = '%s'\n", i, cast(char *)args[i]);
    return 0;
}

运行dmd hello.d则生成可执行文件hello.exe
输出中文则需要setlocale一下:
import std.stdio;

private import std.c.stdio;
extern(C) int setlocale(int, char*);
static this() {
	fwide(stdout, 1);
	setlocale(0, "china");
}

int main()
{
	writef("你好, D!");
	return 0;
}


看看 http://www.digitalmars.com/d/comparison.html中D的特性表:
D Language Feature Comparison Table
Feature                                     D
Garbage Collection                         Yes
<b>Functions</b>
Function delegates                         Yes
Function overloading                       Yes
Out function parameters                    Yes
Nested functions                           Yes
Function literals                          Yes
Dynamic closures                           Yes
Typesafe variadic arguments                Yes
Lazy function argument evaluation          Yes
<b>Arrays</b>
Lightweight arrays                         Yes
Resizeable arrays                          Yes
Built-in strings                           Yes
Array slicing                              Yes
Array bounds checking                      Yes
Array literals                             Yes
Associative arrays                         Yes
Strong typedefs                            Yes
String switches                            Yes
Aliases                                    Yes
<b>OOP</b>
Object Oriented                            Yes
Multiple Inheritance                       No
Interfaces                                 Yes
Operator overloading                       Yes
Modules                                    Yes
Dynamic class loading                      No
Nested classes                             Yes
Inner (adaptor) classes                    Yes
Covariant return types                     Yes
Properties                                 Yes
<b>Performance</b>
Inline assembler                           Yes
Direct access to hardware                  Yes
Lightweight objects                        Yes
Explicit memory allocation control         Yes
Independent of VM                          Yes
Direct native code gen                     Yes
<b>Generic Programming</b>
Class Templates                            Yes
Function Templates                         Yes
Implicit Function Template Instantiation   Yes
Partial and Explicit Specialization        Yes
Value Template Parameters                  Yes
Template Template Parameters               Yes
Variadic Template Parameters               Yes
Mixins                                     Yes
static if                                  Yes
is expressions                             Yes
typeof                                     Yes
foreach                                    Yes
Implicit Type Inference                    Yes
<b>Reliability</b>
Contract Programming                       Yes
Unit testing                               Yes
Static construction order                  Yes
Guaranteed initialization                  Yes
RAII (automatic destructors)               Yes
Exception handling                         Yes
Scope guards                               Yes
try-catch-finally blocks                   Yes
Thread synchronization primitives          Yes
<b>Compatibility</b>
C-style syntax                             Yes
Enumerated types                           Yes
Support all C types                        Yes
80 bit floating point                      Yes
Complex and Imaginary                      Yes
Direct access to C                         Yes
Use existing debuggers                     Yes
Struct member alignment control            Yes
Generates standard object files            Yes
Macro text preprocessor                    No
<b>Other</b>
Conditional compilation                    Yes
Unicode source text                        Yes
Documentation comments                     Yes
以及D与C/C++/C#/Java的对比:
特性 D C C++ C# Java
垃圾收集 Yes No No Yes Yes
<b>函数</b>
函数委托 Yes No No Yes No
函数重载 Yes No Yes Yes Yes
传出(out)函数参数 Yes Yes Yes Yes No
嵌套函数 Yes No No No No
函数文字量 Yes No No No No
动态闭包 Yes No No No No
<b>数组</b>
轻量数组 Yes Yes Yes No No
变长数组 Yes No No No No
位数组 Yes No No No No
内建字符串 Yes No No Yes Yes
数组切片 Yes No No No No
数组边界检查 Yes No No Yes Yes
关联数组 Yes No No No No
强类型定义typedef Yes No No No No
字符串switch语句 Yes No No Yes No
别名 Yes Yes Yes No No
<b>OOP</b>
面向对象 Yes No Yes Yes Yes
多重继承 No No Yes No No
接口 Yes No Yes Yes Yes
运算符重载 Yes No Yes Yes No
模块 Yes No Yes Yes Yes
动态类装入 No No No Yes Yes
嵌套类 Yes Yes Yes Yes Yes
内部(适配器)类 No No No No Yes
协变返回型别 Yes No Yes No No
属性 Yes No No Yes No
<b>性能</b>
内联汇编 Yes Yes Yes No No
直接访问硬件 Yes Yes Yes No No
轻量对象 Yes Yes Yes Yes No
显示内存分配控制 Yes Yes Yes No No
独立于虚拟机 Yes Yes Yes No No
直接生成本地代码 Yes Yes Yes No No
<b>泛型编程</b>
模板 Yes No Yes No No
混入 Yes No No No No
typeof Yes No No Yes No
foreach Yes No No Yes No
约束 Yes No No No No
<b>可靠性</b>
契约式编程 Yes No No No No
单元测试 Yes No No No No
静态构造顺序 Yes No No Yes Yes
确保初始化 Yes No No Yes Yes
RAII(自动析构函数) Yes No Yes Yes No
异常处理 Yes No Yes Yes Yes
try-catch-finally基本块 Yes No No Yes Yes
线程同步原语 Yes No No Yes Yes
<b>兼容性</b>
C风格语法 Yes Yes Yes Yes Yes
枚举型别 Yes Yes Yes Yes No
支持所有C型别 Yes Yes No No No
80位浮点数 Yes Yes Yes No No
负数和虚数 Yes Yes No No No
直接访问C Yes Yes Yes No No
使用现有的调试器 Yes Yes Yes No No
结构成员对齐控制 Yes No No No No
生成标准目标文件 Yes Yes Yes No No
宏文本预处理器 No Yes Yes No No
<b>其他</b>
条件编译 Yes Yes Yes Yes No
Unicode源代码 Yes Yes Yes Yes Yes

D的GC机制使得C/C++的内存分配和指针问题烟消云散一去不返
算是C/C++的一个提升和进步的产物

你可能感兴趣的:(编程,C++,c,C#,D语言)