Last update Sun Sep 8 21:42:01 2013

C and C++ Language Extensions

Extended Type Modifiers

The following type modifier keywords are extensions to the C and C++ standard:

__based, __cdecl, __cs, __declspec, __export, __far,
__fortran, __handle, __huge, __interrupt, __loadds,
__near, __pascal, __ss

These keywords provide support for mixed language programming and for mixed memory models. Although they are not necessary for all applications, their judicious use can significantly enhance program performance.

The keywords __cs, __far, __handle, __huge, __interrupt, __loadds, __near, __ss are applicable for 16 bit programs and are described in 16 Bit Pointer Types and Type Modifiers.

Note: The keywords __far, __interrupt, __handle, __loadds, and __huge are ignored by default in compilations using the Win32 (the default) memory model. Ignore these keywords in any compilation by specifying the -NF compiler option.

For backwards compatibility with legacy code, the keywords _cs, cdecl, _cdecl, far, _far, near, _near, huge, _huge, pascal, and _pascal are also supported. These are incompatible with the language standards, and so should be replaced wherever found with the versions that have two leading underscores.

__cdecl, __fortran, and __pascal

These provide support for calling functions in other languages. For more information, see Mixing Languages.


This keyword aids those programming Microsoft Windows. __export causes the function name to be exported to the linker.

__export may also be used to designate all members of a class for export by adding the keyword between the class and the tag name. For example:

class __export A {...};


Digital Mars C++ supports the Microsoft specific keyword __declspec and the related attributes dllimport, dllexport, naked, and thread. Use __declspec along with an attribute when declaring functions or variables, as described below.

Note: Like other extended keywords, __declspec is disabled with the -A (ANSI compatibility) compiler option.

dllimport and dllexport attributes

Use dllimport and dllexport to import and export functions and data objects to and from DLLs.

The dllimport attribute takes the place of the IMPORTS statement in a module definition file; it indicates that a function resides in a DLL.

The dllexport attribute takes the place of the EXPORTS statement in a module definition file (and the __export keyword). Use it in DLLs to indicate which functions and data objects are available to other applications and DLLs.

The syntax for declaring a function or data object with the dllimport or dllexport attributes is:

__declspec(dllimport) type name(args);
__declspec(dllexport) type name(args);

naked attribute

The compiler does not generate prolog and epilog code for functions declared with the naked attribute. This enables you to use inline assembly code to write your own prolog/ epilog.

The syntax for declaring a function with the naked attribute is:

__declspec(naked) type function_name(args);

thread attribute

Use the thread attribute to declare a variable to be local to a specific thread in a multi-threaded process. The thread attribute is valid only in 32-bit code.

The syntax for declaring a variable with the thread attribute is:

__declspec(thread) type variable_name = expr;

Emit declaration

An __emit__ declaration is used to embed short assembly language fragments into the body of the code. __emit__ takes a variable number of integer arguments, representing the machine language instructions. The compiler then inserts these instructions into the generated code. For example, the declaration

__emit__(0xB47F, 0x89CB, 0xCD21);

and inserts these instructions into the code:

mov AH,7F
mov BX,CX
int 21

It's probably better to use the inline assembler rather than __emit__.

$ in Identifiers

The dollar sign ($) is a valid character in an identifier. This extension is disabled by the -A switch.

Binary integer constants

Constants beginning with the characters 0b are taken to be binary constants. Only the digits 0 and 1 are valid within a binary constant. For example, 0b1101 is a binary integer constant.

Win32 Structured Exception Handling

The __try, __except, and __finally extended syntax to handle Win32 structured exception handling (SEH) is supported. Do not use both C++ and SEH in the same function.
Home | Runtime Library | IDDE Reference | STL | Search | Download | Forums