home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 14 Text / 14-Text.zip / proscons.zip / highc33.txt < prev    next >
Text File  |  1995-01-12  |  15KB  |  298 lines

  1.  
  2. You may recall that some months ago I first encountered Metaware High C++
  3. 3.2a for OS/2, and reviewed it for you all.  Well, Metaware is now
  4. shipping version 3.31 of High C++ for OS/2, which includes several
  5. changes, and I have upgraded.  So it's time for another of my occasional
  6. product reviews.
  7.  
  8. Metaware High C++ is an ISO Standard C and C++ compiler, with versions
  9. available for platforms ranging from OS/2 through AIX to DOS.  High C++
  10. for OS/2 has all of the jazz that you would expect of a professional OS/2
  11. C++ compiler.  It ships with the OS/2 Developers' Toolkit as part of the
  12. package, and all of the tools are native 32-bit OS/2 programs.  If you
  13. have IBM's WorkFrame/2, you can use it to drive High C++, as all of the
  14. necessary "glue" is supplied.
  15.  
  16. High C++ ships with Rogue Wave's Tools.h++ class library (and accompanying
  17. manual).  RW Tools.h++ is a cross-platform set of C++ classes, covering
  18. everything from multibyte strings to file-based BTrees.  Most of the
  19. container classes come in both SmallTalk style and template style
  20. versions.
  21.  
  22. One of the things that I like about High C++ itself is the quality of its
  23. manuals.  Programmers like Good Printed Documentation(tm).  The High C++
  24. manuals qualify.  They are very clear and concise, being sensibly divided
  25. into a Language Reference for general C++ stuff, a Programmer's Guide
  26. dealing with the details of running the actual compiler on OS/2, a Library
  27. Reference dealing with the run-time library (with non-ISO, ISO, and
  28. extra-ISO functions clearly distinguished), a DirectToSOM Developer's
  29. Guide dealing with using DTS C++, and so on.  They are excellently indexed
  30. as well.  Someone at Metaware knows how to use a permuted index tool.
  31.  
  32. Of course, one of the most important things about any compiler is how well
  33. it actually compiles code, and how good its language implementation is.
  34.  
  35. In terms of speed and system requirements, High C++ is not as fast as
  36. Borland C++ (which is still the least hungry OS/2 C++ compiler), but it is
  37. definitely less weighty than IBM CSet++.  The documentation states 10Mb
  38. RAM and 16Mb hard disc (Borland's says 8Mb RAM and uses 20 Mb hard disc)
  39. and I'm here to tell you that it works well in 20Mb RAM (smug grin).
  40.  
  41. The High C++ optimiser has no less than eight levels.  Each individual
  42. optimisation, ranging from dead code elimination through instruction
  43. scheduling to loop unrolling, can be selectively enabled or disabled,
  44. either by compiler toggles on the command line or by pragmas.
  45.  
  46. The compiler will generate code specifically for the 386, 486, or 586
  47. processors, and uses OS/2's floating point support.  Like all other
  48. compilers for Intel CPUs you can also select non-ANSI floating point use
  49. when speed is more important to you than strict ANSI handling of errno.
  50.  
  51. High C++ even has a second optimiser : a multi-file inliner which can be
  52. run during compiliation.  This is capable of inlining way more than the
  53. standard optimiser, including inlining functions in one file that are
  54. defined in another.
  55.  
  56. Another thing that came as a pleasant surprise with High C++ was the
  57. usefulness of the compiler error messages (which can be configured if you
  58. are using tools that expect messages in a specific format).  A lot of the
  59. C++ error messages refer you to the relevant pages in the ARM.  Some of
  60. them are very verbose.  Incorrect use of an overloaded function gives a
  61. list of all the possible overloaded variants on that function, for
  62. example.
  63.  
  64. But this is perhaps the best one :
  65.  
  66.     [c:\temp]type error.cpp
  67.     enum planet { JUPITER, SATURN, URANUS } ;
  68.     int main ( int, char ** )
  69.     {
  70.         planet t = SATUNR ;
  71.         return 0 ;
  72.     }
  73.  
  74.     [c:\temp]hc error.cpp
  75.     MetaWare High C/C++ Compiler R3.31@1
  76.     (c) Copyright 1987-94, MetaWare Incorporated
  77.     E "error.cpp",L6/C11(#222):     SATUNR
  78.     |    Identifier is undeclared; assuming `SATURN' instead.
  79.     1 user error   No warnings
  80.  
  81. Metaware takes great pains to be right up to date in its compiler with
  82. respect to the currently evolving C++ standard, and supplies a host of C++
  83. features, such as namespaces, Run-Time Type Information, exceptions,
  84. exception-aware classes, templates, nested classes, and dynamic casting.
  85.  
  86. Namespaces are a feature new to C++ whereby related classes and variables
  87. can be grouped into a namespace of their own, so that they won't conflict
  88. with other classes and variables of the same name.  The ability to make
  89. C++ classes exception-aware allows you to ensure that instances of your
  90. classes are properly cleaned up when a C++ exception is thrown.  High C++
  91. is the only retail compiler for OS/2 to offer such features.  As far as I
  92. am aware it is in fact the only retail compiler for any platform to do so.
  93.  
  94. Of course, some C++ language features involve implementation complexities,
  95. which can make any programmer's life difficult.  One such problem is the
  96. "single-copy problem" for template instances and virtual function tables.
  97. High C++ offers you two routes to overcome this problem.  You can either
  98. explicitly direct which module of your application will contain which
  99. template instance or virtual function table, or High C++ can link the
  100. application in such a way that multiple copies of a template instance or
  101. virtual function table from separate object files are overlaid to produce
  102. a single copy in the final executable.
  103.  
  104. Unlike some other ISO C and C++ compilers, which usually offer the ability
  105. to compile either C or C++, High C++ offers varying degrees of C and C++,
  106. known as "Incremental strengths".  These go from "plain C" which is ISO C,
  107. through "weak C++" which is ISO C with all of the C++isms added that won't
  108. break existing ISO C code, and "standard C++", which is C++ but allowing
  109. vestigal Cisms, to "full C++" which is C++ with all of the rules strictly
  110. enforced.
  111.  
  112. High C++ lets you control a lot of the things that are "left to the
  113. implementation" by the standards, too.  The default sign of char can be
  114. changed between signed and unsigned, for example.  The alignment and
  115. padding of structures is also controllable.
  116.  
  117. High C++ even supports modifiable function calling conventions.  You want
  118. to call someone else's function that passes parameters left-to-right,
  119. returns a floating point result on the stack, and cleans up the stack for
  120. you upon return ?  No problem squire.
  121.  
  122. High C++ also provides several "one step beyond ISO" optional extensions
  123. to C++ that cover some areas outside of "standard" C++.  Several of these
  124. are simple extensions to C and C++ such as a "long long" integer type,
  125. short and long enumerations, case ranges in switch statements, and numeric
  126. literals in any base (bit manipulation is a lot easier when you can define
  127. the bitmasks in binary, let me assure you).
  128.  
  129. Other High C++ extensions to C and C++ are more profound.  High C++ allows
  130. ADA-style pass-by-name function calling, MODULA-style nested functions,
  131. and "for iterators" which are a generalisation of the idea of a for loop.
  132.  
  133. Another important enhancement to C++ is DirectToSOM C++.
  134.  
  135. SOM is IBM's System Object Model, a CORBA-compliant language-independent
  136. foundation for classes and objects.  It's already used by the Workplace
  137. Shell on OS/2 (allowing WPS to be extended easily), and is the intended
  138. basis for Taligent Application Frameworks.  With most C++ compilers,
  139. writing applications that use SOM involves complex and syntactically
  140. obscure "language bindings" to allow you to use the SOM runtime.
  141.  
  142. Not so with DirectToSOM C++!  DTS C++ allows you to declare and use SOM
  143. classes in your code just as if they were ordinary C++ classes.  You just
  144. write C++ code.  Flick a compiler switch when you compile (or change your
  145. class definitions so that they derive from a SOM base class), and the
  146. compiler itself handles all of the necessary conversion from C++ to using
  147. the SOM runtime.  Even I can use SOM when it is this easy!
  148.  
  149. SOM itself provides features not found in C++ but familiar to object
  150. oriented programmers who use other languages, such as attributes and
  151. metaclasses.  DirectToSOM C++ allows you to use these with a minimum of
  152. variation from normal C++.  Accessing an attribute of a SOM class, for
  153. example, is coded in identical manner to accessing an ordinary data member
  154. of an ordinary C++ class.
  155.  
  156. Similarly, High C++ allows DTS C++ programmers to use features in C++ that
  157. they may be used to, but which are not present in SOM, such as function
  158. overloading, abstract base classes, and C++ exceptions.  This is useful in
  159. cases where the language independence of SOM is not a concern, but where
  160. the increased separation between class use and class implementation that
  161. SOM affords compared to ordinary C++ may be desired.
  162.  
  163. High C++ can also easily turn DirectToSOM C++ class definitions into IDL
  164. for you.  IDL is CORBA's language independent means of describing classes,
  165. that be translated into language bindings for use with other languages.
  166.  
  167. Metaware co-developed DTS C++ with IBM, and has included it in High C++
  168. since version 3.2.  IBM is about to release CSet++ 3.0, which will be its
  169. first DTS C++ compiler.  I have obtained a pre-release copy of CSet++, and
  170. it is not letting the cat out of the bag to confirm from my experience
  171. that SOM binary compatibility works with DTS C++.  A SOM class implemented
  172. using DTS C++ in High C++ can be used, in DLL form and without reference
  173. to the library source, by code written in DTS C++ in CSet++.  What is
  174. more, as long as the SOM rules are adhered to, either may be changed
  175. without affecting the other.  Binary compatibility across C++ compilers is
  176. impossible with standard C++, and easy with DirectToSOM C++.
  177.  
  178. Anyone wanting to use C++ across compilers, or for large projects in a
  179. single compiler where modules may need to be kept separate, should take
  180. note.  With DirectToSOM C++ the future may well have already arrived.
  181.  
  182. High C++ includes several features that are more specific to OS/2
  183. development.
  184.  
  185. As with all OS/2 C++ compilers, the C/C++ run-time library is available as
  186. a static library, or in DLL form.  Compiling and linking a DLL of your own
  187. is as easy as flicking one compiler switch.  If you do not wish to worry
  188. about entering mangled C++ function names into the DEF file, High C++ also
  189. allows you to instead mark functions as "exported" in the source, using
  190. __declspec(dllexport).
  191.  
  192. High C++ also provides full support for multithreaded applications.  Of
  193. course, the Standard C library is provided in a multithreadable form, and
  194. compiling code that uses it is again a simple matter of flicking a single
  195. compiler switch.  Unusually for an OS/2 C++ compiler however, in High C++
  196. the iostreams portion of the C++ run-time library can also be safely used
  197. from multiple threads.  What is more, High C++ allows you to declare your
  198. own variables as thread-safe using __declspec(thread), and it will handle
  199. keeping different copies of the same variable for each thread for you.
  200.  
  201. Since I have now been using High C++ for some time, I can comment on more
  202. longer term aspects of High C++ than I could in my last review.  I've been
  203. able to throw quite complex code at the compiler, I have played around
  204. with some of its features in greater depth, and I have also had experience
  205. of Metaware's technical support.
  206.  
  207. Although I was initially slightly skeptical of some features, such as
  208. nested functions and for iterators, they have been proven by the ultimate
  209. test, which is that they turned out to be very useful in practice.
  210.  
  211. I can report that the tech support is excellent.  When I discovered a
  212. problem in DirectToSOM that gave the compiler indigestion (as I said, I
  213. have been able to explore more of the boundaries of some features) the
  214. folks at Metaware corrected the compiler and provided a free update.
  215. There wasn't a hint of my having to wait until the next major update for
  216. the bug fix.
  217.  
  218. There are weaknesses in High C++ of course.  But not many.  The debugger
  219. (MDB) is text-mode and quirky (rather like Watcom's old WVIDEO), and
  220. there's no IDE (apart from Workframe).  But then again, some people prefer
  221. their favourite programmer's editor (BOXER in my case) and makefiles...
  222.  
  223. As I said before, although High C++ is not perfect, I enjoy it.  It is an
  224. excellent compiler for the professional C++ programmer.
  225.  
  226. You may be put off by the high price compared to other OS/2 C++ compilers,
  227. but then you have to ask yourself whether they include Rogue Wave's
  228. Tools.h++, DirectToSOM C++, namespaces, exceptions, RTTI, for iterators,
  229. nested functions, incremental strength C++, "one touch" DLL generation,
  230. easy multithreading, ...
  231.  
  232. If you want to contact Metaware to find out more, here's the gen :
  233.  
  234. C u s t o m e r   S e r v i c e       MetaWare Incorporated
  235. * 30-day money back guarantee         2161 Delaware Avenue
  236. * 90-day warranty (free upgrade)      Santa Cruz CA 95060-5706
  237. * Free tech support by: phone,        internet: techsales@metaware.com
  238.   fax, email, bulletin board          tel: (408) 429-6382
  239. * Major upgrades are chargeable       fax: (408) 429-9273
  240.  
  241. » JdeBP «
  242. » Jonathan de Boyne Pollard, FIDONET 2:440/4.0, JdeBP@donor2.demon.co.uk «
  243. -----------------------------------------------------------------------------
  244.  
  245. Topical aside :
  246.  
  247. I have a Pentium at work, and when I learned of the bug in the Pentium
  248. floating point division instruction, I was naturally interested in seeing
  249. it for myself.  So I compiled one of the widely circulated example
  250. programs :
  251.  
  252.     #include <stdio.h>
  253.     int main ( int, char ** )
  254.     {
  255.         double x = 4195835.0, y = 3145727.0;
  256.         double z = x - (x / y) * y;
  257.  
  258.         printf("%f\n",z);
  259.  
  260.         return 0;
  261.     }
  262.  
  263. This program should print 256.000000 on a Pentium, and 0.000000 on a 386
  264. or 486.
  265.  
  266. When I first compiled it with High C++ 3.31a, it printed 0.000000 on my
  267. Pentium, which was the wrong (i.e.  correct) answer!  When I looked at the
  268. generated code using Metaware's debugger, I realised that High C++ had in
  269. fact recognised that the calculations cancelled each other out, and had
  270. optimised them away, reducing the program down to, in effect :
  271.  
  272.     #include <stdio.h>
  273.     int main ( int, char ** )
  274.     {
  275.         printf("%f\n", 0.0);
  276.         return 0;
  277.     }
  278.  
  279. I hadn't even turned optimisation on.  This was with the default
  280. optimisation!  Bypassing this did yield the correct (i.e.  wrong) result
  281. on my Pentium.  So the bad news is, I suppose, that my Pentium is wrong
  282. just like everyone else's.  (-:
  283.  
  284. When I received the fix to the compiler for my DirectToSOM problem, I was
  285. also told that Metaware plans to release a feature to fix problems caused
  286. by FDIV, and that the update to the compiler that they were sending me
  287. actually included a preliminary version of this feature.
  288.  
  289. So I nosed around a bit and found it.  There's a new compiler toggle,
  290. Pentium_safe_divide_code.  When I turned it on, and recompiled the above
  291. program, High C++ generated extra code around the FDIV instruction that
  292. at runtime would replace it with a call to a library routine if necessary.
  293.  
  294. So (since my copy already appears to have it) it looks like Metaware is
  295. going to be the first C++ compiler vendor to release a workaround for the
  296. Pentium FDIV bug.
  297.  
  298.