Switching to Digital Mars C++ from Borland
This chapter describes the differences you should consider when converting code written for Borland C++ Version 4.0 to Digital Mars C++.- Keywords
- Predefined macros
- Header files
- Libraries
- Memory model support
- Assembly language interface
- Compiler options
Keywords
Digital Mars C++ supports many of Borland C's nonstandard keywords. The following table lists Borland's extended keywords and their Digital Mars counterparts:
Unsupported Borland keywords | Digital Mars counterparts |
---|---|
_cs | __cs |
_ds | No equivalent |
_es | No equivalent |
_saveregs | No equivalent |
_seg | No equivalent |
_ss | __ss |
Predefined Macros
Digital Mars C++ supports many of Borland C's nonstandard macros. The following table lists Borland's extended macros and their Digital Mars counterparts:
Unsupported Borland macros | Digital Mars counterparts | comments |
---|---|---|
__BORLANDC__ | __DMC__ | works the same, but version numbers are for DMC |
__BCPLUSPLUS__ | __DMC__ | works the same, but version numbers are for DMC |
__CDECL__ | No equivalent | |
__COMPACT__ | __COMPACT__ | |
__DLL__ | _WINDLL | |
__HUGE__ | No equivalent | |
__LARGE__ | __LARGE__ | |
__MEDIUM__ | __MEDIUM__ | |
__MSDOS__ | No equivalent | |
__PASCAL__ | No equivalent | |
__OVERLAY__ | No equivalent | |
__SMALL__ | __SMALL__ | |
__TEMPLATES__ | No equivalent | |
__TINY__ | __TINY__ | |
__TCPLUSPLUS__ | __DMC__ | works the same, but version numbers are for DMC |
__TURBOC__ | __DMC__ | works the same, but version numbers are for DMC |
_Windows | _WINDOWS |
Header Files
The Digital Mars C++ run-time library includes all the Borland non-standard headers. Many of these headers simply reference the Digital Mars header file that contains equivalent functions. Digital Mars C++ issues a warning whenever code uses a header file. In general, we recommend switching to ANSI-compliant headers wherever possible.Library Functions
Digital Mars C++ supports most Borland library functions. The table below lists those Borland functions that the Digital Mars C++ run-time library does not support:
Unsupported functions | Borland header | Comments |
---|---|---|
Graphics functions | graphics.h | |
Text display functions | conio.h | |
_dos_getvect | dos.h | |
_dos_setvect | dos.h | |
_harderr | dos.h | |
_hardresume | dos.h | |
_hardreturn | dos.h | |
_OvrInitEms | dos.h | |
_OvrInitExt | dos.h | |
_setcursortype | conio.h | Use display package functions |
cgets | conio.h | Use display package functions |
cprintf | conio.h | Use display package functions |
cputs | conio.h | Use display package functions |
closedir | dirent.h | |
cscanf | conio.h | |
dostounix | dos.h | |
farheapcheck | alloc.h | |
farheapcheckfree | alloc.h | |
farheapchecknode | alloc.h | |
farheapfillfree | alloc.h | |
farheapwalk | alloc.h | |
getpass | conio.h | |
getvect | dos.h | |
harderr | dos.h | |
hardresume | dos.h | |
hardreturn | dos.h | |
heapcheck | alloc.h | |
heapcheckfree | alloc.h | |
heapchecknode | alloc.h | |
heapfillfree | alloc.h | |
heapwalk | alloc.h | |
import | dos.h | |
importb | dos.h | |
intr | dos.h | |
opendir | dirent.h | |
outport | dos.h | |
outportb | dos.h | |
readdir | dirent.h | |
rewinddir | dirent.h | |
setvect | dos.h | |
unixtodos | dos.h |
Some Digital Mars C++ run-time library functions have different types or numbers of arguments from their Borland counterparts, return different values, or support different defined constants. For information on specific functions see the Runtime Library Reference.
Borland Graphics Interface
Digital Mars C++ does not support any of the functions, fonts, or drivers in the Borland Graphics Interface.Memory Models
The Digital Mars C++ implementations of those 16-bit memory models also supported by Borland C++ (the Tiny, Small, Medium, Compact, and Large models) are similar. Their significant differences include:- In the Digital Mars Compact and Large models, unlike their Borland counterparts, the stack and data segments are not the same. Near pointers in these models are relative to the data segment and cannot access automatic or parameter variables. Check your assembly language source code to ensure that SS is not assumed to be equal to DS.
- Digital Mars' malloc() functions take an unsigned int as an argument for 16-bit memory models and take an unsigned long for 32-bit models. Therefore, the 16-bit models limit the size of a data object to 64KB blocks. To allocate a block greater than 64KB, call farmalloc, which takes an unsigned long.
- At program startup, Borland's memory-management routine allocates all available DOS memory as one block of far heap space. In contrast, Digital Mars C++ makes a call to DOS for each request for far heap space.
- Digital Mars C++ does not support these additional non-standard Borland memory-management functions: heapcheck, farheapcheck, heapfillfree, farheapfillfree, heapwalk, farheapwalk, coreleft.
Huge memory model support
Digital Mars C++ does not support the Huge memory model. That is, a pointer whose type is unspecified cannot be made huge by default. However, the compiler supports huge pointers and huge data (via the huge modifier).Digital Mars C++ does not support the Borland halloc and hfree functions. Convert calls to these functions to the corresponding Digital Mars far calls (which have unsigned long argument types and can, therefore, allocate huge blocks) or store the affected data in a different structure (a huge array, for example).
Assembly Language Interface
The Digital Mars C++ assembly language interface is very similar to Borland's. The only differences are:- DS is not equal to SS for the Compact and Large memory models.
- For C functions (those declared as __cdecl and extern "C"), double and float values are returned in registers, rather than in a static memory location. For C++, FORTRAN, and Pascal functions, double and float values are returned on the stack in a manner compatible with Borland C.
- In Digital Mars C++, structs, floats, and doubles are returned by allocating a temporary variable on the stack and passing a hidden pointer to it. The called function copies the return values into this variable and returns a pointer to it.
- Digital Mars C++ does not support the _FLAGS register variable.
- Digital Mars C++ does not store long double values as 10-byte quantities; they are the same as doubles (8 bytes).
Compiler Options
Digital Mars C++ provides a wide range of compiler command line options, many of which perform operations similar or identical to a Borland C++ compiler option.
To convert Borland compiler command lines to the most similar Digital Mars command lines possible, use the BCC utility. BCC automatically converts Borland C++ command lines to DMC command lines and then runs DMC.