Switching to Digital Mars C++ from Microsoft
This chapter describes differences you should consider when converting code written for Microsoft Visual C++ Version 1.5 to Digital Mars C++.What's in This Chapter
This chapter discusses compatibility issues between Microsoft Visual C++ and Digital Mars C++ with respect to these issues:- Keywords
- Predefined macros
- Header files
- Libraries
- MFC
- Memory model support
- Assembly language interface
- Compiler options
Keywords
Digital Mars C++ supports most of Microsoft C's nonstandard keywords. The following table lists Microsoft's keyword extensions and their Digital Mars counterparts:
Unsupported Microsoft keywords |
---|
__fastcall |
__fortran |
__saveregs |
__segment |
__segname |
__self |
Predefined Macros
Digital Mars C++ supports most of Microsoft C's nonstandard macros. The following table lists Microsoft's extended macros and their Digital Mars counterparts:
Unsupported Microsoft macros | Digital Mars counterparts |
---|---|
_CHAR_UNSIGNED | _CHAR_UNSIGNED |
_FAST | No support |
_MSC_VER | __DMC__ (works the same, but version numbers are for SC) |
_MSDOS | Recommended use is as a command line argument |
MSDOS | Recommended use is as a command line argument |
_PCODE | No support |
_QC | No support |
M_I286 | M_I286 |
M_I386 | M_I386 |
M_I8086 | M_I8086 |
M_I86 | M_I86 |
M_I86CM | M_I86CM |
M_I86HM | No support |
M_I86LM | M_I86LM |
M_I86MM | M_I86MM |
M_I86SM | M_I86SM |
M_I86TM | M_I86TM |
Header Files
The Digital Mars C++ run-time library includes all the Microsoft nonstandard headers. Many of these headers simply reference the Digital Mars header file that contains equivalent functions. Digital Mars C++ issues a warning whenever your code makes use of such a header file. In general, we recommend switching to ANSI-compliant headers wherever possible.Library Functions
Digital Mars C++ supports the great majority of Microsoft Visual C++ Version 1.5 library functions. The table below lists the only Microsoft functions that the Digital Mars C++ run-time library does not support:
Unsupported functions | Microsoft header | Comments |
---|---|---|
Graphics functions | graph.h | Digital Mars C++ does not support the DOS graphics system. |
Charting functions | pgchart.h | |
Virtual memory functions | vmemory.h | Digital Mars C++ no longer supports Virtual Code Management (VCM). |
QuickWin functions | io.h | |
_bexpand | malloc.h | Use farrealloc instead. |
_bfree | malloc.h | |
_bfreeseg | malloc.h | |
_bheapadd | malloc.h | Not needed with Digital Mars C++ heap management. |
_bheapchk | malloc.h | |
_bheapmin | malloc.h | |
_bheapseg | malloc.h | |
_bheapset | malloc.h | |
_bheapwalk | malloc.h | |
_bmalloc | malloc.h | |
_bmsize | malloc.h | |
_brealloc | malloc.h | |
_dieeetomsbin | math.h | |
_dmsbintoieee | math.h | |
_expand | malloc.h | Use realloc instead. |
_fexpand | malloc.h | Use farrealloc instead. |
_fheapchk | malloc.h | |
_fheapmin | malloc.h | |
_fheapset | malloc.h | |
_fheapwalk | malloc.h | |
_fieeetomsbin | math.h | |
_fmsbintoieee | math.h | |
_heapadd | malloc.h | Not needed with Digital Mars C++ heap management. |
_heapchk | malloc.h | |
_heapmin | malloc.h | |
_heapset | malloc.h | |
_heapwalk | malloc.h | |
_j0, _j1, _jnl | math.h | |
_j0l, _j1l, _jn | math.h | |
_nexpand | malloc.h | Use realloc instead. |
_nheapadd | malloc.h | Not needed with Digital Mars C++ heap management. |
_nheapchk | malloc.h | |
_nheapmin | malloc.h | |
_nheapset | malloc.h | |
_nheapwalk | malloc.h | |
_setbnew_handler | new.h | |
_sethnew_handler | new.h | |
_y0, _y1, _ynl | math.h | |
_y0l, _y1l, _yn | math.h |
Microsoft Foundation Classes
Digital Mars C++ for Windows and DOS includes the Microsoft Foundation Classes Version 2.5, for the Large memory model only. Digital Mars C++ for Win32 includes 32-bit MFC 3.0.Digital Mars' versions of the Microsoft Foundation Class Library are licenced from Microsoft Corporation.
When compiling code that uses the Microsoft Foundation Classes, use the -gf option (see Compiling Code).
Memory Models
The Digital Mars C++ implementation of those 16-bit memory models also supported by Microsoft C (the Small, Medium, Compact, and Large) is similar, but not exactly the same. The significant differences are:- In the Digital Mars Compact and Large models, unlike their Microsoft counterparts, the stack segment and data segment are not the same. Near pointers in these models are relative to the data segment and cannot be used to access automatic or parameter variables. Check your assembly language source code to ensure that SS is not assumed to be equal to DS.
- Microsoft C only creates a far data segment if the amount of data exceeds 32,767 bytes, or exceeds the value specified via the /Gt option to CL (Digital Mars C++ has a corresponding compiler option, -GT). While data is always assigned to the near data segment by default, functions are near by default in the Compact model and far by default in the Large model in Digital Mars C++.
- Digital Mars' malloc() functions take an unsigned int as an argument for all 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, a Microsoft C program's heap management run-time allocates _amblksiz bytes of far heap space. Additional heap is allocated in _amblksiz blocks as needed. In contrast, Digital Mars C++ makes a call to DOS for each request for far heap space.
- Unlike Microsoft C, Digital Mars C++ does not allocate heap blocks of zero size if a program requests them. NULL is returned instead.
- Unlike Microsoft C, Digital Mars C++ cleans up free heap space when a program releases a block of memory.
- Digital Mars C++ does not support the Microsoft C _heapadd, _bheapadd, and _nheapadd functions because its heap manager calls DOS each time a program requests far heap space.
- Digital Mars C++ does not support the Microsoft _expand, _bexpand, _fexpand, and _nexpand routines. Use realloc in place of _expand or _nexpand calls (or wherever possible), and farrealloc in place of _bexpand or _fexpand. However, be aware that realloc and farrealloc, unlike _expand, can move the block to a new location to satisfy the reallocation request, in which case they will return the new location of the reallocated block.
- Digital Mars C++ does not support these additional non-standard Microsoft memory management functions: _heapchk, _bheapchk, _fheapchk, _nheapchk, _heapwalk, _bheapwalk, _fheapwalk, _nheapwalk, _heapset, _bheapset, _fheapset, _nheapset, _heapmin, _bheapmin, _fheapmin, _nheapmin.
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++ also supports the Microsoft halloc and hfree functions.
Support for based pointers
Digital Mars C++ does not support a based heap. No support for based pointers is available except for:__based(__segname("_CODE")); __based(__segname("_DATA")); __based(__segname("_STACK"));If your code makes use of based pointers, convert them to far pointers. Based pointers are a nonstandard construct and the code generated using them is not significantly better than for far pointers.
Assembly Language Interface
The Digital Mars C++ assembly language interface is very similar to Microsoft'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 or extern "C"), double and float values are returned in the registers, rather than in a static memory locaton. For C++, FORTRAN, and Pascal functions, double and float values are returned on the stack in a manner compatible with Microsoft 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.
Compiler Options
Digital Mars C++ provides a wide range of compiler command line options, many of which perform operations similar or identical to a Microsoft compiler option.To convert your old Microsoft compiler command lines to the most similar Digital Mars command lines possible, use the CL utility. CL automatically converts Microsoft command lines to dmc command lines, and then runs dmc.