www.digitalmars.com [Home] [Search] [CTG] [RTL] [UGR]

Switching to Digital Mars C++

Digital Mars C++ offers numerous advantages over other compilers, both in programmer productivity and in the speed and robustness of generated code. Switching to Digital Mars C++ is well worth the effort. This chapter outlines general considerations for converting existing code.

What's in This Chapter


Portable Programming Practices

Some of the programming practices that help make code portable and reusable also help make it compatible with Digital Mars C++. Your code will be easier to convert if you:

Object Level Compatibility

Digital Mars C++ object modules are "broadly compatible" with Microsoft and Borland objects. However, there are some differences:

Using Third-Party Libraries

If you must use third-party libraries written for Microsoft or Borland C++ with the Digital Mars C++ compiler, there is no simple way to determine which features are compatible. Your code could even link correctly and still contain obscure errors.

If you have the source to the third-party library, try recompiling it with Digital Mars C++. A better solution is to obtain the Digital Mars version of the library from the vendor. Recompiling for Digital Mars C++ In many cases, converting programs written for another compiler to Digital Mars C++ can be as easy as recompiling them. Here are some steps you can take to ease recompilation:

Compile time warnings

By default, the Digital Mars C++ compiler generates warnings in response to more conditions than do most other compilers. If you find these unfamiliar warnings annoying, compile with the -w (warning level) option. Each instance of -w on the SC command line turns off a specific warning. For example, the command:
	sc -w2 -w6 myfile.cpp 
turns off warnings number 2 and 6. For information on warnings and their numbers, see Chapter 2, "Compiling Code."

Converting 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 
	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 	Microsoft 	Comments
	functions	header 

	Graphics functions graph.h	Digital Mars C++ does not 
					support the DOS graphics 
					system. 

	Charting functions pgchart.h
	 
	Virtual memory	vmemory.h	Digital Mars C++ no longer 
	functions			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 Chapter 2, "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 SC command lines, and then runs SC.


Converting 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

Digital Mars C++ supports many of Borland C's nonstandard keywords. The following table lists Borland's extended keywords and their Digital Mars counterparts:
	Table 24-1 Support for Borland nonstandard keywords 
	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:
	Table 24-2 Support for Borland C++ nonstandard macros 

	Unsupported Borland macros Digital Mars counterparts 

	__BORLANDC__	__DMC__ (works the same, but 
				version numbers are for SC) 
	__BCPLUSPLUS__	__DMC__	(works the same, but 
				version numbers are for SC) 
	__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 SC 
	__TURBOC__	__DMC__ (works the same, but 
				version numbers are for SC) 
	_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:
	Table 24-3 Unsupported Borland library functions 
	Unsupported 	Borland header	Comments
	functions 

	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 Run-Time 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:

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:

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 SC command lines and then runs SC.


Copyright 1995-2001 Digital Mars. All Rights Reserved.