C++ Compiler Review - Part 2
Written by Gordon Zeglinski
The second installment to our compiler review appears in this issue. We will look at Borland C++ version 2.0 for OS/2 and Metaware High C/C++ version 3.32. In addition to featuring these two compilers, the results of a series of benchmarks will be presented. The benchmarks were cut down from the set listed in the last issue due to time constraints.
These two compilers are at opposite ends of the user spectrum. Borland C++ is a low cost quick compiler, with a good IDE. Metaware is at the high end of the cost spectrum, supports numerous target environments, and is really designed for those seeking the ultimate performance.
Borland C++ version 2.0
The Borland package requires about 60 megs of HD space to install. The package includes PM and text mode compilers and debuggers. The OS/2 2.1 toolkit is also included. The PM mode compiler is part of the IDE. In addition to tools to help convert Windows resources to OS/2 resources, there is an OS/2 version of TASM. (Personally, TASM is my favorite assembler.) Only OS/2 is supported by this package, however; to do DOS and Windows applications the Windows version must be purchased. A nice feature is that OWL (Object Window Library) is now supported under both PM and Windows.
This is the fastest compiler evaluated. It is significantly faster than Watcom 10a, which is the second fastest compiler evaluated. On the flip side the code produced by Borland is slower than that of all the the compilers. As far as RAM requirements go, this system was easily able to handle them. It supports C++ exceptions, templates, run time type identification, and the new style casts. As can be expected, moving from the DOS/Windows version is fairly easy especially if you use OWL, although the BGI functions are not included in the OS/2 version. The CRTL is designed to work around the problem of OS/2 not unloading and loading DLLs in a guaranteed order (which does cause problems in CSet 2.1 under certain circumstances). While on the topic of the CRTL, complete source code to the CRTL, OWL and class libraries is included on the CD version.
Like VAC++, Borland had problems compiling one of the C++ test objects.
The PM IDE has a built in debugger and compiler. It follows the same design as the Windows and DOS IDEs. The built-in editor is one of the best I've used. Although the IDE is not as open or flexible as Workframe/2, it is very capable of handling complex projects. One bug I noticed is that in the IDEs project "memory", it does not store the fully qualified path to the project file. Thus, unless the current working directory happens to be the same as the project file, the memory feature is useless.
The IDE also contains a code browser. With the browser, one can examine both C and C++ code. Function chains can be followed. In the case of C++, object hierarchies and objects can be explored. The browser could use some threading on startup and there should be an easy way to "Backup". Each time you open a new more detailed browser view, the previous view disappears. It would be useful to be able to "backup" to the less detailed view.
Borland is the only compiler package that ships with a decent resource editor. Borland's dialog editor is the best part of the resource package. The resource workshop is less featured than their windows counter part. The editor may have problems on some systems working with icons, and bitmaps. If the resource editor was as good as their Windows resource workshop, it alone would nearly justify buying this package. Unfortunately it is almost identical to the version shipped in version 1.0.
The most noticeable change from version 1.0 is the improved stability. The debugger doesn't offer any PM-specific debugging aids. However, the debugger has an appealing design and is easy to use. Its a lot easier to view a pointer as an array in Borland's debugger than in C-Set++'s debugger. It has no scripting capability, unfortunately.
In keeping with Borland tradition, there's a lot of documentation. The documentation is well written and useful to new and experienced programmers. The manuals themselves seem to be made of low grade paper and bindings. The quality of the material is below that of the Metaware or Watcom manuals, but the ease of use exceeds that of the Watcom manuals. The following manuals are included:
Overall, the package shows great improvements in some areas and little improvement in others. In particular the lack of improvement to the resource workshop is most annoying. The compiler supports more C++ features than either C-Set++ or Watcom and is extremely fast. This makes it an ideal compiler for new programmers. At the same time, the PM version of OWL allows programmers to create code that runs under both Windows (using the Windows version of the product) and OS/2.
Metaware High C/C++ version 3.32
The Metaware package requires about 13 megs of HD space to install. The package includes text mode debugger, the OS/2 2.1 toolkit, and Tools.h++ by Rogue Wave. Installation was pretty simple. Although the package only includes support for OS/2, Metaware has versions of the compiler available for DOS, Windows, and various flavors of unix.
The compiler is slow but generates fast code. The error messages generated by the compiler are very precise and make fixing compile time errors fairly easy. High C/C++ has the most complete C++ implementation of any of the reviewed compilers. It supports templates, C++ exceptions, run time type identification, name spaces, new type casting methods, and C++ iterators. In addition to having the most complete C++ implementation, Metaware was a pioneer in Direct To Som (DTS) technology and High C/C++ was the first OS/2 compiler to support DTS.
High C/C++ has tighter C syntax rules than the other C compilers but it supports many nice extensions. For instance, you can compile C code in "Incremental C++ mode". This allows you to use C++ features in a C program without all the syntax rules of C++ being enforced. Case statements can support ranges like, "case 'A'..'C':". There are many more extensions.
Virtually every aspect of the optimizer can be individually toggled on and off. The compiler has switches and #pragmas to configure just about everything. This is both good and bad. It's good because it allows you to remove an optimization that may be causing a bug or affecting performance adversely or cause some other strange side effect. It's bad because you can play with switches and pragmas for a long time if you get into it.
Support for IBM's Workframe/2 version 1.x is included. No native IDE is provided.
The debugger is useable although awkward in interactive mode. It's essentially a command line debugger wrapped loosely with a menu system. For instance, a local variable display can be accessed through a menu option. However, when the local variable view window is open, it's not possible to step the debugger.
The powerful scripting language allows one to create a batch file for debugging an application. Combine the powerful script support with the poor interactive support, one ends up with a debugger that is best suited for batch debugging.
The documentation covers covers the various operating systems supported by the compiler. This allows one to plan for cross platform support. Even though multiple operating systems are included in the same manuals, they do not suffer a reduction in readability. The indexes are organized well, making it easy to find information. I find these manuals to be among the best I've ever used. The following manuals are included:
Although the compiler is slow, it produces fast code and good diagnostic messages. When it comes to C++ and DTS support, this compiler is the leader. If you need an interactive debugger, though, you will probably have to find one that supports Metaware. In addition, you will have to get PM specific debugging aids from a DevCon CD or someplace else.
We finally get to the benchmarks. As I mentioned previously, the benchmarks were scaled down a bit. The following table shows the results of the C benchmarks:
The units for the C benchmarks are as follows. Bsort and Sieve are in seconds (the smaller the number the better). Dryhstone 21 is in Dhrystones/sec. The two whetstone tests are in KWhets/sec. All the Linpack tests are in Kflops. With the exception of the first two benchmarks, larger numbers are better.
The following table show the results of the C++ benchmark.
Test 1 simply tests the construction and destruction of an object including a call to its virtual function.
Test 2 is like test 1 except a more complex object is used.
Test 3 is similar to test 1 except that the object is created/destroyed from within a try/catch block.
Test 4 is like test 3 except that an exception is actually thrown and caught.
Test 5 assigns the complex object to another object. The same complex object that was used in test 2 is used here.
Test 3 uses 1 less function calls than test 1. In theory, it should use up less time than test 1 unless the amount of time used to setup the try/catch block exceeds that of a function call. In both the Metaware and Borland test results, test 3 was faster than test 1. The following table shows the compilation time and executable size for the C++ bench mark program.
The unzip test compares the compilation time, executable speed, and executable size for Info unzip version 5.12. The following table shows the results of the unzip test.
The command line used to test executable speed was unzip -t unzip512.zip >NUL.
Although VAC++ compiled unzip faster than Watcom, this is usually not the case. VAC++ takes twice as long to compile the AdeptXBBS source code. Automatic function inlining had to be turned off in VAC++ because the resulting EXE falsely reported error in a good zip file. Metaware had inlining turned on.
The source code to the C and C++ benchmark programs is included, along with the .cmd files used to compile the executables. The raw output from the benchmarks is also included. The executables are not included to keep the size of the distribution down.
So you're probably wondering which compiler is the best compiler for OS/2 programming. When I started this series, I thought I'd be able to say definitively that compiler XXX is the best without a doubt. Unfortunately it's not that easy because no single compiler is the best. Below I'll try to give some guidelines on what I think each compiler is best suited for.
The Metaware compiler has the best OOP support around. It was the first compiler to support direct to SOM and has the most complete C++ implementation of the reviewed compilers. Its code optimizer is one of the best so if code speed is important then this compiler is worth considering. It's definitely not for the hobbyist, however.
The Watcom compiler can generate executable for almost every PC operating system. This makes it the choice for cross platform development. In addition, Watcom usually makes the smallest executables. Unfortunately the compatibility problems with Warp make version 10a less than perfect, though version 10.5 should fix these problems. Watcom is a great "mid level" package - it generates fast code with the smallest executable size. Watcom is such a versatile package it's great for the novice programmer as well as the professional.
Visual Age C++ has the highest system requirements. Although at present it needs a few CSDs, once these are released, it should be the ideal compiler for people needing to make large cross platform projects. Although the package only supports OS/2, it is available on several other hardware platforms and operating systems. The "Open Class" library abstracts windowing, threading and more from the application. This allows a high degree of code reusability when moving the application to another environment supported by VAC++. This package is definitely not designed for the hobbyist. Professional programmers with some serious hardware that want to do visual programming should consider this package.
Borland C++ is the quickest compiler of the ones we have looked at. In general, its optimizer isn't as good as the other 3 compilers. Through OWL, one can create PM and Windows programs from the same source without too much difficulty. (Of course to do Windows programming, you have to purchase the Windows version of the compiler.) The Windows version has a lot more polish than the OS/2 version. Borland is a good choice for a beginner programmer and those who are familiar with OWL.