Current Notes February 1987 L E A R N I N G C W I T H M E G A M A X C A Preferred Choice for the Beginner Review by Stephen D. Eitelman Although the C-programming language has been around for several years, it is only recently that it has become popular in the microcomputer community. This has been attributed to the advent of 16-bit machines with their faster CPU's and much larger memories. Megamax-C has been reviewed extensively (see what is hoped is a fairly complete bibliography of reviews at the end of this article; BYTE has not yet reviewed it). So why do we need another review? In reading the various reviews, I was struck with one common characteristic of both the authors and the apparent audience: They all seemed to be very accomplished C-programmers. What seemed to be needed was a review written from the point of view of a beginner. The reviews I found all had another common characteristic: They all were favorable to Megamax-C. One of the reviewers was downright exuberant, even to the point of really liking the editor in spite of its obvious deficiencies. None of the reviews addressed the concern here: Is Megamax-C well suited to the beginning C programmer? Well,in a word, YES! Even though it is relatively expensive (about $200), I feel that it is well worth the cost. Buying a cheaper compiler "just to learn on" is probably a waste of money because of the many likely deficiencies of such a compiler. WHAT THE BEGINNER NEEDS There seem to me to be at least four needs that are important to a beginner in C that are perhaps not so important to the experienced C-programmer. Let's take a look at each. Speed in compiling and linking. A beginner is going to make a LOT of mistakes in syntax as well as program logic. Writing a program for a compiler requires first writing the source code with an editor. Then the compiler must be called up and run. At this point, most compilers (probably all) will report the syntax errors. Then the editor must be recalled, the source code called up and corrected. Then re-compiled. Then the linker must be called up and run to include the standard libraries, relocate the whole thing in memory and do other sorts of housekeeping chores. More errors usually get uncovered at this point. So back to the edit cycle, then compile, then link and finally run the finished program. Whereupon, the hapless programmer discovers a logic error. And so, once again, back to the edit-compile-link cycle. If this all sounds rather tedious, it is!! If the compiler and linker are slow, it becomes infuriating. Lattice-C nearly drove me crazy waiting for it each time through the cycle. Without a fast compiler package, the motivation to learn C will soon be lost to frustration. A complete implementation. I have used a subset of the standard C (on an IBM-PC) and as soon as I departed from the tutorial and began - ST 1 ST - Current Notes February 1987 experimenting, I found severe limitations. The usual omission is a floating point math package; additionally, in this case, the (standard input/output header) file was automatically included. Error messages resulted from trying to include it explicitly. There were other similar changes. This is terribly frustrating to a beginner who is having enough trouble trying to understand the language in its standard form without having to contend with serious departures. Thorough and clear documentation. An experienced programmer has a wealth of previous knowledge to draw upon when the manual is lacking; not so the beginner. Virtually every step of a novice's program is going to generate questions, especially when trying to resolve the error message listing. A poorly written manual is going to result in more de-motivation. Ease of use. A large number of compiler and linker options serve mainly to confuse the newcomer. The majority of ones effort can easily switch from learning C to learning the intricacies of an extremly flexible package. MEGAMAX HAS IT ALL The bottom line of applying these four criteria is that Megamax-C is superior in all four; I can vouch from personal experience that it is much faster, the documentation is much more complete and it is easier to use than Lattice-C. Furthermore, the reviews indicate that it is without a doubt the fastest of all the available C compiler packages for the 520/1040ST in compiling and linking. If it is used in conjunction with a RAM disk, its speed is blinding! A short addition program compiles from RAM disk in about three seconds and links in eleven seconds. It produces the most compact code according to the benchmarks in the STart review. The speed of execution of finished programs is also very fast. In the DHAMPSTONE test, it was the fastest in two of six categories. In three of the remaining four categories, it lost the race by an insignificant amount. In the final case (manipulation of doubles), it was the slowest by a large margin. In my own test of doubles, cosine squared of J for J from 1 to 10000, Megamax was 2.35 times faster than Lattice-C as opposed to 7.2 times slower reported in STart's DHAMPSTONE test. So much for benchmarks! Megamax-C is also a full implementation of the Kernighan & Ritchie C-language; there are no unpleasant surprises when trying to do the exercises in a C textbook or trying to venture off on one's own. However, this version is not fully compatible with the extensions or the AES/VDI calls in Alcyon-C that has been used to write much of the software in the sample C programs in the Current Notes ST library. One of the more instructive exercises, however, is trying to convert these programs to Megamax-C, so this is not a real disadvantage. DOCUMENTATION The manual is a thick three ring binder that is well-indexed; there - ST 2 ST - Current Notes February 1987 is no table of contents which I found to be somewhat of a nuisance. It contains excellent coverage of the AES and VDI calls to the ST's GEM operating system. In fact, the coverage in these areas is very nearly tutorial. There are a total of 17 chapters and three appendices. Some omissions are evident: there is no discussion of the floating point math routines nor is there a detailed discussion of the standard set of keywords; it is apparently assumed that the user is familiar with them. As far as I could tell, the keywords all conform to the K&R standard. The first page in the book is labelled "Read This First". That is always a comfortable feeling -knowing where to begin! They describe disk configurations and it is at once clear that this is one package that can be used with only one floppy disk drive. The manual is NOT a text book. For learning the C-language, a good text must be chosen; Waldenbooks, B.Dalton Booksellers, bookshelves at computer retailers, and local libraries are all good sources of books on the C-language. And they have certainly proliferated. The standard reference is The C Programming Language by Brian W. Kernighan and Dennis M. Ritchie. Every article on C says you must have it, so I will too: you must have it. But frankly, it's very hard for the beginner to use. It is just too concise. But it's all there. The book I have used for some time now and quite like is C Programming Guide by Jack J. Purdum. It is written very clearly and goes into the detail necessary for a beginner, but stops short of smothering the reader. The author has also written an excellent companion guide titled C Self-Study Guide which is done in workbook fashion with lots of problems to work through. Each chapter includes answers to the problems written in a style reminiscent of Schaum's Outlines. Also, there is a tutorial series of articles in Analog magazine's ST Log section written by Claynum Walnum. This series gets about as much teaching done in as few words as I can imagine. The series began with the February 1986 issue and continues. THE COMPILER, LINKER, AND SHELL The compiler is called a single pass compiler. This means it only goes through the source code once. This may sound trite, but it's not: most compilers go through the code at least twice and some more than that. The single pass compiler is very fast because of its single pass. The compiler averages 6.92 times faster than the other compilers covered in the two STart reviews shown in the bibliography. But how they handle forward address references in a single pass, I just cannot fathom. The only complaint I have seen is that files are limited to 32K bytes long. Tsk, Tsk. How often is this going to be a limitation for the beginner? I certainly have not bumped up against it. For the advanced programmer, there is a chaining capability, so it is not really a limitation. The linker is also quite fast; the comparisons in the two STart reviews show times averaging 2.58 times faster than the linkers in the other packages. Now for my one complaint: The cursor control arrangement in the editor is very awkward. The arrow keys do not move the cursor; instead - ST 3 ST - Current Notes February 1987 they move a "viewing port" (the screen) around on a large sheet fixed in space on which the text is printed. The rather disconcerting effect is that the left arrow key moves all of the text to the right; the right key moves text left; the up arrow key moves text down and the down key moves text up. Additionally, there are two cursors: one is the usual blinking rectangle that marks the position of the next character. The other is Megamax's version of the mouse arrow, a vertical line with crow's feet on each end. The only way to move the text cursor is by moving the mouse cursor and then clicking on the new position, meaning removal of one's hands from the keyboard. I found this entire arrangement so annoying that I stopped using their editor. A very simple solution turned out to be to substitute a word processor for EDITOR.PRG; I used 1ST Word and have been very happy with it, although there is no automatic indenting. The Shell is a delight to use. It is GEM-based and one only has to select from the drop down Execute menu to get the editor, linker, disassembler, librarian, compiler," other" (executable program) or "make" facility. All the commands are menu and dialog box based, so there is no need to learn command line protocols. There is a Locate drop down menu to set the drive on which the various pieces of the compiler package are located if their locations are different from the one on which the shell is located. SUMMARY I think Megamax-C is the preferred choice of a compiler for a beginning C-programmer. It is fast in compilation and linking, produces very compact code, executes very rapidly, and is easy to use. It is a complete implementation of Kernighan and Ritchie C and offers what is probably the best documentation on the market today. It's a little expensive at $200, but should serve the beginner and the advanced programmer alike extremely well. A word of caution is in order: This article was based solely on my own experiences while learning C. These experiences are not necessarily representative of the needs of others. So read the reviews in the bibliography and decide if my claims as to what is important apply to you before buying. BIBLIOGRAPHY Anders, Arick. "Mark Williams C & Menu+."STart, the ST Quarterly. pg. 104-107, Winter, 1986. (Not a Megamax-C review, but should be read before buying a C-compiler package.) Anders, Arick and Michael Bendio. "Which C For Me?" STart, the ST Quarterly. pg 63-73, Fall, 1986. Fleishman, Mike. "Megamax C 'Don't even think about another C compiler' ." Antic. pg 67-68, September, 1986. Miller, George. "Megamax C." Compute!'s Atari ST Disk and Magazine. pg 32,34, October, 1986. - ST 4 ST - Current Notes February 1987 The 1986 ST Buyers Guide. "Megamax C (353)." STart, the ST Quarterly. pg 75, Winter, 1986. Weir, Douglas. "Megamax C and Mark Williams C." Analog ST-Log. pg 75ST-77ST, November, 1986. Megamax C, $199.95, Megamax, Inc., Box 851521, Richardson, TX 75085. (214) 987-4931. - ST 5 ST - ermine the correct order of execution in case the cards were shuffled. Punch cards were succee