digitalmars.com                        
Last update Sun Sep 8 21:42:02 2013

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

Digital Mars C++ supports most of Microsoft C's nonstandard keywords. The following table lists Microsoft's keyword extensions and their Digital Mars counterparts:

Table 23-1 Support for Microsoft keywords
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:

Table 23-2 Support for Microsoft C nonstandard macros
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:

Table 23-3 Unsupported Microsoft library functions
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:

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:

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.

Home | Runtime Library | IDDE Reference | STL | Search | Download | Forums