Classic Computer Magazine Archive CREATIVE COMPUTING VOL. 11, NO. 11 / NOVEMBER 1985 / PAGE 88

Alcor C - a serious, comprehensive implementation. (Tandy gram) (evaluation) Jake Commander.

In this column a few months back, I took some space to extol the virtues of the C language. Well, I am as adament as ever: I still think C is just about the best language for everyday use by a programmer. It is easy to learn and develop programs in the language and to produce fast, working code in a fraction of the time required to do it in assembly language.

Admittedly, Basic has its uses. It is there in ROMf there is no need to load a compiler or interpreter. And it is possible to become addicted to it because of its simplicity. For example, it is a relatively easy task to open a file, do something with it, and write a new output file containing the manipulated input file.

What takes you five minutes in Basic might take you 20 minutes in C. But so what? The resulting program will probably be machine code running at the raw speed of the microprocessor instead of interpreted speed as with Basic.

For as long as I have been programming in C on my Model 4, I have been using my own 75% completed C compiler. This has some strange side effects in that writing programs for a compiler that is only three-quarters finished means that you become awfully proficient in a subset of the language. Only as each new function becomes integrated into the compiler do you get a chance to exercise that particular feature. For example, my present compiler does not yet support C-type structures (a way to define variables that are accessed as a group). So whenever I program in C on my TRS-80 I have to kludge my way around any problem that involves groups of variables. This isn't really a big deal, because other languages don't support entities like structures, so I tend to use the same techniques I used in a Basic program. (That is one of the reasons I am convinced Basic programmers should find a switch to C relatively easy.) Nevertheless, it is frustrating not to be able to use the entire language on my Model 4.

Alcor C

In that frame of mind, imagine my unrestrained enthusiasm at the prospect of reviewing a complete C compiler. It was my good fortune to receive a review copy of a fully-fledged C compiler with all functions intact--including my heretofore missing features. This compiler is part of the Alcor C advanced programming system from Alcor Systems, 13534 Preston Rd., Suite 365, Dallas, TX 75240. I remember promising a review of this package a while back, and it is a pleasure to recommend it highly.

I knew it was going to be good as soon as I saw that 1.25" thick manual. At last on my TRS-80 I have a rich set of operators and features guaranteed to keep an avid C programmer happily hacking into the small hours. This package is a serious implementation of the C language and is comprised of many functional parts. This doesn't mean it is difficult to use though; there are a couple of reasons why there are several different modules. First, alcor's C development system is very versatile. For each way of using the system, there is a different program to support that feature.

Secondly, C itself is a very versatile language. Although comprised of only a few keywords and operators, it is very flexible. As a result, any compiler that hopes to support the entire C language must itself be quite large. Now we bump our heads against the fact that the humble TRS-80 has a mere 48K of RAM (usually) available for programs other than the operating system or Basic. So any code over and above this (if there is going to be room for I/O and edit buffers and such) must be split into parts. The disk operating system itself is split up for just this reason. Hence it makes sense for Alcor to have split their C compiler into logically distinct pieces.

In fact, the compiler consists of five parts: the main compiler and four overlays, each of which deals with a specific part of the C language. This segmentation is normally invisible to the programmer who just sits back and waits for the result when a program is being compiled. However, Alcor's C compiler is busily loading and running whichever module is required at any given point in the compilation process.

Alcor states in their documentation that for the sake of efficiency there are ways to write C code which (to couch it in the vernacular) give the compiler a break. By using common sense in the layout of a program, you can minimize the swapping of compiler overlays. This involves only such disciplines as defining C constants all together in a contiguous section of code. If you don't follow these guidelines, nothing comes out and slaps you on the wrist; it just takes longer to compile your program. The compiler, left to its own devices, does run quite fast. Although by no means the fastest I have ever seen, it is more than adequate for serious work on the TRS-80.

Creating the Source Code

Before inputting anything to the compiler, of course, you must create the source code. This can be done with either a word processor or a text editor, but a text editor is usually preferable. This is the case with the Blaise text editor provided with the Alcor C package, which lets you enter program text and do the usual things like find and replace strings, insert and delete characters, etc. It also provides features that are unlikely to be included in a word processor but are extremely useful to a programmer.

For example, an auto-indent feature is provided. If you want to indent your program text to set it off as a separate loop or whatever, the editor will take your lead as to where to start the next line. If, for example, your program reaches a point where characters start at line position eight, instead of making you tab to that position on each new line, this text editor will tab to position eight whenever you hit RETURN. This continues until you change the start position of the next line or turn the feature off.

The editor also neatly gets around the lack of some of the keyboard characters on the TRS-80 such as left and right square brackets, curly braces, tilde, and other symbols that are important in the C language. (Please Tandy, give us these keys!) Alcor's editor provides these characters by using the CLEAR key as an escape character. For example, to get an underline character, you hit CLEAR and then the 7 key. If you are a Model I user with no way even to display these characters, Alcor allows alternate characters to be used in their place. Unfortunately, this saddles you with an ugly non-standard C notation, which I guess still beats not being able to use C at all. In total, ten extra characters are provided by this method.

The Blaise editor program is a screen-oriented text editor, which means that you can scroll around the screen at will, hopping from one line to another, making alterations at will. You are not confined to editing single lines of text as in old fashioned Microsoft Basic. I must say I found the editor a cinch to use--it is enough of an improvement over my previous editor to convince me to make it my current editor of choice.

I found a couple of the text editor commands a little wordy. For instance, to direct the editor to jump to a certain line for editing, you go into the command mode with a CLEAR-C, then type the command SHOWLINE followed by a line number. I would have thought it would have been much simpler to use a CLEAR-J for JUMP OR CLEAR-G for GOTO followed by a line number. I am a lousy typist and need all the help I can get when sending an editor to a specific line--CLEAR-C SHOWLINE 100 is too many characters for such a simple exercise.

One feature I liked which could have been taken a stage further is the ability to undelete a line. This allows you to recover from a mistakenly deleted line and also to undelete a line to a new position. It is a pity that the feature can be used on only a single line at a time.

Compilation

The Alcor C compiler takes the source code that has been produced by the editor (which is assumed to have an extension of/C) and outputs a file to disk with the same name but with an extension of /OBJ for object. As it goes through its compilation process, the screen displays the text that is currently being compiled.

The object file output from the C compiler can be processed in one of four ways. If desired, it can be used immediately after being output as an object file by the compiler. To do this, you use a runtime interpreter called RUNC.

This program takes a /OBJ file and interprets it. This is because in its normal mode of operation, the C compiler outputs what is called p-code. An abbreviation of pseudo-code, p-code is understandable only to a specially written interpreter--in this case the RUNC program. P-code has certain advantages that make it popular in many development languages. It tends to be very compact, allowing for very small programs, and it saves having to link the compiled program with any libraries (such as floating-point arithmetic routines) it may need to use. All these runtime libraries are in fact part of the RUNC interpreter program. So to test your C program, all you have to do is type RUNC followed by your program name.

Other options allow different modes of execution of the compiled program. Two programs, OPTIMIZE and CODEGEN, in the Alcor C development package can manipulate the compiled program to produce an enhanced version. Version.

OPTIMIZE takes a p-code object file and scans the code looking for redundancies and long-winded code. Because a compiler is only an automatic process, it can never output code of the same caliber that a human programmer can. The optimizer cleans up the more obvious pieces of inefficient p-code. Alcor claims that it will reduce the size of a program by between 10 and 30%.

The CODEGEN command takes p-code and converts it to machine code directly executable by the Z80. This makes the code run extremely fast, because the RUNC interpreter is now bypassed completely. However, converting the p-code to machine code involves an enlargement of the program; it may take two or three machine code instructions to represent a single p-code instruction. Therefore the resultant program will be two to three times larger but will execute much, much faster.

All three of the above types of object file can be input to yet another program called LINKLOAD. This utility is the all-important linking loader which allows separately compiled programs and/or libraries to be linked. It is this program that produces a stand-alone machine code version of your C program which can be executed directly from DOS. Libraries allow disk file manipulation, string handling, single and double precision floating-point number crunching, and character input/output. These are all linked with your C program using LINKLOAD. To their great credit, Alcor doesn't even ask for a royalty on any code you sell using their runtime libraries. All they require is documentation of the fact that your code contains Alcor runtime support.

Documentation

The documentation that comes with such an extensive package as this is obviously of extreme importance. Thankfully, Alcor has taken the time and effort to get this right. The manual is about as complete as anyone could wish. Over 400 pages in length, the documentation is as comprehensive to the complete neophyte as to the advanced C user. The manual is divided into volumes covering the editor, the compiler, the runtime interpreter, and the object-code utilities. The library functions are described in full (and there are lots of them).

There is even a huge tutorial covering the C language itself which is useful both as a tutorial and as a refresher on parts of the language used infrequently.

There is a great deal of information in this hefty tome. Happily, it has even been laid out with care. Paragraph headings jump out. Examples are set apart and clearly labeled. Lots of white space keeps the whole thing digestible. Even the editors of Creative Computing would have a hard time improving on it. Myself, I can't find fault with it. Maybe I should complain about the color of the cover or something just so as not to sound too sycophantic.

There is one other advantage of this thick manual for Alcor Systems. Anybody wishing to pirate a copy of this package will think more than twice. You see, nobody in his right mind is going to copy 400 double-sided pages of text. Without the text you ain't got the package, and that's just the way it should be. Alcor deserves all the revenue from this superlative work. I recommend it. Highly. If this package had been available four years ago, IBM wouldn't have stood a chance.

Products: Alcor C (computer program language)