What's in This ChapterThis chapter discusses compatibility issues between Microsoft Visual C++ and Digital Mars C++ with respect to these issues:
- Predefined macros
- Header files
- Memory model support
- Assembly language interface
- Compiler options
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|
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|
|_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|
Header FilesThe 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.
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.|
|Virtual memory functions||vmemory.h||Digital Mars C++ no longer supports Virtual Code Management (VCM).|
|_bexpand||malloc.h||Use farrealloc instead.|
|_bheapadd||malloc.h||Not needed with Digital Mars C++ heap management.|
|_expand||malloc.h||Use realloc instead.|
|_fexpand||malloc.h||Use farrealloc instead.|
|_heapadd||malloc.h||Not needed with Digital Mars C++ heap management.|
|_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.|
|_y0, _y1, _ynl||math.h|
|_y0l, _y1l, _yn||math.h|
Microsoft Foundation ClassesDigital 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 ModelsThe 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 supportDigital 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 pointersDigital 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 InterfaceThe 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 OptionsDigital 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.