REVIEWS COURTESY OF ZXSR

HiSoft C
HiSoft
1984
Sinclair User Issue 33, Dec 1984   page(s) 138,139

A LANGUAGE FOR THE FUTURE

Adam Denning lays bare the mysteries of C, a new language for the Spectrum which is faster than Forth and simpler than Pascal.

Memory: 48K
Price: £25.00

If the Spectrum was pitched against the BBC Micro for serious applications, it would not be at all surprising if it came out on top amongst programmers. That is almost entirely due to the efforts of one small software company up in Bedfordshire, Hisoft.

The company's release of its acclaimed Pascal compiler over a year ago, coupled with the simultaneous release of its machine code development system Devpac, has gained it and the Spectrum a higher credibility factor than Sinclair Research could ever manage by itself.

Now the company has released another compiler, this time for the language C. C is widely regarded as the language of the future, not least because of its unique position as the language in which Unix™ is written. Unix is now the de facto standard operating system for any 16-bit computer, with versions even available for the 68000 extended BBC Micro and soon the QL.

C is integral to all that, gaining a reputation as the systems language most likely to succeed. It has two main advantages over other languages like Basic and Pascal: First, C is standard, so programs are in practice portable - as opposed to the theoretical portability of Pascal and the mess created by the myriad versions of Basic. Second, it is block structured and far less formal than rivals of the Pascal ilk.

Two long words here, both of which need definition. A portable language is one which has exactly the same form on all machines, which means a program written in language X on machine Y will run without alteration on another machine Z that also supports language X. Only C gets truly close to that level of portability.

A block structured language is one in which each task in a program is broken down into small, easily manageable modules. That type of programming is much in vogue, with Pascal being the most shouted-about progenitor. The trend probably started with the BCPL language, developed by Dr Martin Richards in Cambridge, but Pascal and C soon became more widely used.

BCPL is in fact the grandfather of C, as two Americans, Dennis Ritchie and Brian Kernighan, took the offspring of BCPL - called B - and came up with C. The only book worth reading on C was written by those two Americans, and is called The C Programming Language published by Prentiss Hall and costing £16.95.

So the Spectrum now provides more opportunity for the budding systems programmer than any other home micro widely available. The provision of C gives distinct advantages to the Spectrum owner, as it is compiled into Z80 machine code and therefore runs faster than most other languages available - it beats the hell out of Forth.

Moreover, anyone contemplating a career in computing is going to need to know about the language, and this is the cheapest option there is. The average programmer will also find it useful as it is easier to use than Pascal and easier to learn. It can do almost everything which Spectrum Basic can do without any of the disadvantages.

Hisoft C is supplied on a cassette, containing everything - the compiler, the editor, the standard input/output header and a library of useful system routines. Once loaded the program asks if you wish to save the compiler and editor to microdrive. That follows Hi- soft philosophy of making all its products microdrive compatible, so that a user equipped with those devices need never be hampered by having to return to cassette tapes again.

The editor supplied as an integral part of the compiler is the standard Hisoft line editor used on all its source code based products, but programs can be written without recourse to the editor once you are familiar with both C and the implementation. The editor is invoked by pressing CAPS SHIFT and 1, i.e. EDIT, simultaneously, and from thereon all functions are standard until the c commnd is used to return to the C compiler.

C programs created that way can be saved to and loaded from tape or microdrive, and of course any section of saved source can be included in a compilation with the #include directive. That is standard practice in C compilers as it is usual for at least one header file containing all the #define definitions and standard i/o to be included in the source file.

Hisoft C has something else which, as far as we know, is unique - programs can be entered directly into the compiler just by typing them in, and subsequently invoked either by telling the machine that the end of the source file has been reached - by pressing SYMBOL SHIFT i - or by going into direct mode with #direct+ and typing a suitable invocation such as:

main();

That direct mode also means that individual functions can be tested as stand alone programs, or quick calculations can be done. For instance, you might want to know the hexadecimal equivalent of 23456. All you have to do (assuming you are in direct mode) is type:

printf("%x/n", 23456);

and your answer will be printed out. You can leave direct mode by typing #direct-.

Before we look at some C programs and discuss how to use the language, we must look at some of the imperfections of the current version of Hisoft C. The most noticeable of those is that invocation of a non-existent function resets the machine, losing the compiler and returning to Basic.

The float type is also missing, which means that floating point numbers cannot be operated on. Oddly, the scanf function - the C equivalent of INPUT - is not here either, but it is fairly simple to write the parts of the function that you require.

Those are really the shortcomings worth mentioning, and even those will not be there for long. Hisoft will give a free update to purchasers of the current version of the compiler, and all the facilities mentioned as lacking are going to be included at some stage.

A program consists of a number of functions, of which one must be called main. That is where execution begins when the program is run. Of course, Hisoft's direct mode obviates the need for that, but it is best to follow the standard language definition so that later program development on other machines will not be hindered by silly mistakes.

The program in Figure 1 converts any number between 0 and 65535 into its hexadecimal and binary equivalents - a bit simple, perhaps, but then how many of us have programmed in C on the Spectrum before?

The program is simpler than it looks, but introduces a lot of C's more interesting properties. It was very hurriedly written, so it is by no means the best example of C programming.

The first thing we do in all three functions is to declare our variables, so that main has two integer variables and a character string (an array) 16 characters long, readn has three integers and a smaller string array and binary has two integers.

The only function that returns a result is readn, and the type of that result is indicated by declaring the function itself as having a type - integer in this case.

We also see that binary has two parameters passed to it. We have to tell it what type those parameters are, which is the purpose of the two lines after the function declaration.

The body of the program is controlled by main. It first prints a prompt and then uses our readn function to read in a decimal number, passing the integer value to the variable n. The binary function is then called to convert this into a 16 character binary string in the array b, and then the answers are printed out. The printf function can handle the printing of numbers in hex, but not binary, so we then use a for loop to print out the 16 digits of b in reverse order.

Notice the structure of the 'for loop' - the start value first, then the end condition and finally the increment. The ++ here is just the C way of incrementing.

As carriage returns and various other 'non-printing' characters are rather hard to represent on screen, C uses the backlash (\) as an escape character, so that various symbols after the slash are converted to various characters. Thus, \n is a new line character.

The readn function is a very simple method of reading in a number from the keyboard, and has two distinct disadvantages. It can only handle digits, so no sign must be included, and if you type in more digits than there are places in the s array, you will crash the computer. It is, however, quite fast. It simply reads in each digit from the keyboard at a time, using the getchar function until it finds a new line character. The != symbol means 'not equal to'.

The resulting string is then converted to decimal by taking each digit and progressively adding into ten times the total - a very standard method. That is then returned as the result.

A 'for loop' is also used by binary, this time decrementing from 15 to 0 to access each element of the array in reverse order. We use bitwise ANDing (the & operator) on powers of two to generate each binary digit. Each power of two is formed by shifting one left the requisite number of places (the << operator - pure BCPL).

That is by no means the extent of C's usefulness, and its reputation for systems programming is well founded but difficult to demonstrate briefly. It is the most welcome addition to the Spectrum catalogue since Sinclair introduced the Microdrives, and at the price cannot be missed. Hisoft is at: 180 High Street North, Dunstable, Bedfordshire. Tel. 0582 696421.


REVIEW BY: Adam Denning

Gilbert Factor9/10
Transcript by Chris Bourne

ZX Computing Issue 28, Aug 1986   page(s) 29

Hisoft
£25

Hisoft's compiler costs £25 and consists of a tape cassette with the compiler on one side, the 'C' library on side 2, and two manuals. The main manual, 78 pages in length, provides instructions on how to use the compiler and text editor, with a reference section giving differences of Hisoft's implementation of 'C' to the standard of Kernigham and Richie. There is also a chapter explaining error messages.

The second booklet explains upgrades of version 1.3 (the second issued version of this compiler) and responds to deficiencies reported by users in the original version.

Once the compiler is loaded, the user is given the option to save the compiler to microdrive. The library routines on side two can also be transferred to microdrive once in the editor routine.

The compiler is very simple to use, and Hisoft's package is ideal if you are learning to program in 'C'. Pressing 'EDIT' takes you into the text editor. When typing in a program, the text editor assigns each line a number. Line numbers are not part of the language of 'C', but they are used to simplify text editing. Once a program or routine is complete, compilation is simply a matter of returning to the compiler (pressing 'c), then typing 'include'. The compiler appears to operate, unusually, in a single pass. Many of the standard 'C' routines are built into the compiler so there's often no need to access the library. If the compiler finds any errors, it stops to present an error number, line number, and short error message, of course, the actual error may not be on the line indicated (and the compiler did sometimes gets its line numbers mixed up), but with very few key presses the programmer can return to the text editor, edit the offending line, then back to the compiler for another try.

Once all bugs are removed, the programmer indicates 'end of file', and the compiler asks if you want to run the program, and if the reply is yes, the compiled program is executed.

In this mode, the compiler, text editor, text file and compiled code all exist in RAM at the same time, so the amount of space for 'C' programs is rather limited. The object code generated in this manner cannot be saved independently; to use a 'C' program in another session, the text file must be saved to tape or cartridge, then compiler and text file loaded at the next session, then the source file re-compiled and run. Alternatively, use of the 'translate' command in the source file causes the compiled code with run time routines to be dumped to tape, for use independent of the compiler. Compiled code can only be used when loaded to a start address of 25200, leaving just enough space for a short BASIC boot program.

A feature very useful for beginners is the library; as it is in source code, the library can be loaded into the text editor and many lessons learnt from examining the routines. User routines can be added to the library, and Hisoft promise to add routines periodically. Library routines are added to the user programs with the 'include' command. A special variant of this command, '?include?' searches the library, and only includes routines which are required by the user program.

Hisoft's compiler offers integer arithmetic only, but otherwise it is an excellent, easy-to-use package, ideally suited to both beginner and computer professional.

Before moving onto the QL compiler, it's worth making the point that neither package offers any tutorial on 'C'. Both manuals make frequent reference to Kernigham and Richie's book. This is a must for professionals, although beginners may find one of the cheaper books, mentioned earlier, easier to use.


REVIEW BY: David Nowotnik

Transcript by Chris Bourne

All information in this page is provided by ZXSR instead of ZXDB