D programming Language



Download 1.66 Mb.
Page42/47
Date08.01.2017
Size1.66 Mb.
#7507
1   ...   39   40   41   42   43   44   45   46   47

COM Programming


Many Windows API interfaces are in terms of COM (Common Object Model) objects (also called OLE or ActiveX objects). A COM object is an object who's first field is a pointer to a vtbl[], and the first 3 entries in that vtbl[] are for QueryInterface(), AddRef(), and Release().

COM objects are analogous to D interfaces. Any COM object can be expressed as a D interface, and every D object with an interface X can be exposed as a COM object X. This means that D is compatible with COM objects implemented in other languages.

While not strictly necessary, the Phobos library provides an Object useful as a super class for all D COM objects, called ComObject. ComObject provides a default implementation for QueryInterface(), AddRef(), and Release().

Windows COM objects use the Windows calling convention, which is not the default for D, so COM functions need to have the attribute extern (Windows). So, to write a COM object:

import com;
class MyCOMobject : ComObject

{

extern (Windows):



...

}

The sample code includes an example COM client program and server DLL.


D vs Other Languages


This table is a quick and rough comparison of various features of D with other languages it is frequently compared with. While many capabilities are available with libraries, this table is for features built in to the language itself.

Feature

D

C

C++

C#

Java

Garbage Collection

Yes

No

No

Yes

Yes

Functions
















Function delegates

Yes

No

No

Yes

No

Function overloading

Yes

No

Yes

Yes

Yes

Out function parameters

Yes

Yes

Yes

Yes

No

Nested functions

Yes

No

No

No

No

Function literals

Yes

No

No

No

No

Dynamic closures

Yes

No

No

No

No

Covariant return types

Yes

No

Yes

No

No

Arrays
















Lightweight arrays

Yes

Yes

Yes

No

No

Resizeable arrays

Yes

No

No

No

No

Arrays of bits

Yes

No

No

No

No

Built-in strings

Yes

No

No

Yes

Yes

Array slicing

Yes

No

No

No

No

Array bounds checking

Yes

No

No

Yes

Yes

Associative arrays

Yes

No

No

No

No

Strong typedefs

Yes

No

No

No

No

Aliases

Yes

Yes

Yes

No

No

OOP
















Object Oriented

Yes

No

Yes

Yes

Yes

Multiple Inheritance

No

No

Yes

No

No

Interfaces

Yes

No

Yes

Yes

Yes

Operator overloading

Yes

No

Yes

Yes

No

Modules

Yes

No

Yes

Yes

Yes

Dynamic class loading

No

No

No

No

Yes

Inner classes

No

No

No

No

Yes

Covariant return types

Yes

No

Yes

No

No

Performance
















Inline assembler

Yes

Yes

Yes

No

No

Direct access to hardware

Yes

Yes

Yes

No

No

Lightweight objects

Yes

Yes

Yes

Yes

No

Explicit memory allocation control

Yes

Yes

Yes

No

No

Independent of VM

Yes

Yes

Yes

No

No

Direct native code gen

Yes

Yes

Yes

No

No

Templates

Yes

No

Yes

No

No

Reliability
















Design by Contract

Yes

No

No

No

No

Unit testing

Yes

No

No

No

No

Static construction order

Yes

No

No

Yes

Yes

Guaranteed initialization

Yes

No

No

Yes

Yes

RAII

Yes

No

Yes

Yes

No

Exception handling

Yes

No

Yes

Yes

Yes

try-catch-finally blocks

Yes

No

No

Yes

Yes

Thread synchronization primitives

Yes

No

No

Yes

Yes

Compatibility
















Algol-style syntax

Yes

Yes

Yes

Yes

Yes

Enumerated types

Yes

Yes

Yes

Yes

No

Support all C types

Yes

Yes

No

No

No

Long double floating point

Yes

Yes

Yes

No

No

Complex and Imaginary

Yes

Yes

No

No

No

Direct access to C

Yes

Yes

Yes

No

No

Use existing debuggers

Yes

Yes

Yes

No

No

Struct member alignment control

Yes

Yes

Yes

No

No

Generates standard object files

Yes

Yes

Yes

No

No

Macro preprocessor

No

Yes

Yes

No

No

Other
















Conditional compilation

Yes

Yes

Yes

Yes

No


Download 1.66 Mb.

Share with your friends:
1   ...   39   40   41   42   43   44   45   46   47




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

    Main page