Home
C Vu Volume 1 Issue 3 PDF
Contents
1. E also accessible with the source line as it is executed with the result this is a structured BASIC EXIT the above are multiline constructs indeed you re cautioned that STRING 80 d ther for you T ELEV is immediate partial the LIST command pu and auto indents loop constructs etc ts all q to quit the editor and flags any context errors rror will to print off the contents trace back procedu or with the change point of the BASIC compilation this keywords in upper case then the if drop you into the of variables or set them res very Similar in appearance to the VM CMS REXX it slows also supported with the statement age height TRON command t of each sub expression printed out INT n better it allows you to this lists each trace mode the structured statements and there is no necessity for line BASIC down if you use line TYP GI eg EGE and space reserved for them with the DIM statement eg DIM fred jim person Structure and array fred jim or fred jim You can have REMarks for comments BASIC DEF FNx const ruct instead statement allows one procedure process The parameters are passed procedures to have side effects as with C global or static variables Lastly it is possible to so that it BASIC or by runb the
2. printf s Sd EBUGO S Note that if DE hat any DEBUGO having to brace the used the DEBUGO can BUG is not defined printf with i be used sm the DI ring containing the name of the current wo things that are very useful to know in a debug message two symbols but are accesable inside othe ach side of r ma ere then is the first of my debug macros is with an example parameters looks like function calls the effect into the code of the macro definition The MAC macro above simply If vl was a parameter it could not be assigned the building our debug tools is the Cc ra the definition to in the source file and FILE _ t file being processed that the macro processor defines RA ro definitions The macro _ LINE _ is the current line is a Th S ar LIN D direct Here we come across a difference b tw thought The printf function can rn constant strings that EBUGO in the code will dissappear if DEBUG is not defined fdef The only way around this is to have a accept different numbers of arguments Here is one This means Instead of macro has no body EBUG endif in the code every time it is y in place of the printf n macros and functions that requires some take a variable number of argumen above macro can only take one argument s
3. 9 Never call a function without checking its error return If the error is impossible at least call assert as in this example if close fd 1 assert FALSE 10 Check null pointers against NULL never against 0 or anything else Do not cast NULL if flurb x y struct Rcd NULL bad 11 When you have an initialization a test and an incrementation use a for loop instead of a while loop This makes the loop control more explicit and reduces the possibility of forgetting to increment 12 When calling a function that returns a useful value or an error return use this assign and check paradigm if p fcn x y NULL handle error While ordinarily I would recommend against doing assignment in the middle of an Volume 1 C Vu Issue 3 expression this is an exception It occurs so often that it s immediately recognizable to th xperienced reader requiring no time to figure out Non experienced readers should learn about it 13 Never read anything from a human user without checking it thoroughly for errors and reporting problems back precisely For example if the user hits Control D or Control Z don t give a conversion error message This rule prohibits the use of scanf in most cases 14 Don t use lousy functions just because they re in the library What some library contributors know about programming you could fit in your left e
4. Change Of Address As of 24th March 1988 Sahara have moved from Vauxhall to South Bank Technopark 90 London Road LONDON SE1 6LN Tel 001 922 3350 The more astute amongst you will notice that this puts Sahara on the same site as their parent company MicroAPL who have announced APL 68000 under Mirage The Omnis3 database and application generator is now available as is the OxSys business suite Additions amp Changes The major addition to the latest revision of Mirage is an archiver allowing the easy backup of hard disks to floppies Some utilities notably the spooler have been enchanced and bugs fixed The Pascal compiler has also been updated And Finally Volume 1 C Vu Issue 3 Sahara Software run a number of Mirage oriented courses for everyone from new users to system programmers Further details can be obtained from David Eastwood at Sahara STRUCTURE PART 3 By Colin Masterson In this series we have been considering how to achieve structure in our programs and have identified some key issues To produce a structured program we must Concentrate initially on high level tasks Recognise special cases Produce simple single entry exit processes Understand the problem Now we have said nothing so far about how you are solving the problem the algorithm or methods you are using but concentrated on how you go about laying out the chosen method So perh
5. Unix Utilities 3 source for LEX lexical analyser for MS DOS but should be possible to convert to other OS s Unix Utili ties with volume 17 contain lo related to yet compiler including ts of the LEX amp 4 together these material YACC another compiler language systems 10 11 12 13 14 NEW 19 NEW 20 Issue 3 C Language Tutorial 2 the example programs to accompany the text found on volume 9 Communications several comms protocols Kermit SEAlink and library managers Arc Lump Squeeze and some related utilities PC Utilities 1 some of which are provided as executables only Contains an extensive shareware window manager cursor control progs from Bill Sparrow EGA graphics routines Languages 2 two subset C compilers cpcn and ratc with sources an interpreter sci as MS DOS executable only and a number of Unix style utilities Games 1 the Dungeons and Dragons style game Larn Should be possible to get it running on most systems Requires lots of memory to run Minix 1 conversion of the Kermit comms program Conversion and documentation of use to any Minix devotee by Adrian Godwin Unix Utilities 6 mainly a healthy bunch of
6. cell DYNACALC beta the printout that is book type headers and r and foot lcheck Mail ers appear like By batch Lograph in order to run it version of the Upg it Cc from the manual I can see that in Visicalc and as a consequenc it bears a more to Lotus Though it has no macros and Label cell Again it can perhaps be best characterised as to This was acceptable for expect something a bit slicker is on its way like its 8 bit ls do not spill into ter either the old n is to use keys second is using a least most of the command causes There is one the next merge is a perfectly adequate Spellcheck is a I mean that you despite this rade was to me at predecessor than a passing the next medium function Volume 1 C Vu Issue 3 SCULPTOR Sculptor is a 4th generation language and database system once known under the name of SAGE that is also available for MS DOS tm and Unix It would require a full article on its own in order to do it full justice Sculptor comprises of a number of utility programs which are based around two interpreters The first is sage this is designed to run programs which interact with the user through menu s and panels to allow database updates and enquiries etc The second is sagerep which is designed around printing out reports There ar ffectively two levels of use of Sculptor the first is using
7. nt 6809 version bu Once in insert like control B markup language line to be cent formatting is done fo mode you format for bold and control U similar to ROFF to set r you to see d on noticeable ommis ion f footers Page Title on odd pages and Chapter Title on even pages With Stylograph come Mailmerge and Spell system for running off Stylograph documents as standard letters spellchecker with a extendable dictionary have to save your document and quit Styl batch it is adequate I can t really comment about this as my missing the keyboard definition file for Dynacal However this moment Chapter press t on a 16bit machine you the screen as well as on rom the markup language on Ee the text r som in two ways for underlin and you execute that opt text load a file so you can from the shell type a command like function wordprocessor versions of both are available for Stylograph s roots show through a ree and a half mode word processor Lt save a file Issue 3 as the shell will load the Like the The modes are This is keys tion if you The spool text and some In this mode you for up ten TOT xt you hav The first Th For headers and footers the at ce xampl by this I mean when the head Page its ancestry is
8. pack a procedu can no longer be edited or debugged BASIC runtime suppo assignment is allowed eg or use ram isa by reference functions re EEn a comment each prog this compresses but it can be BASIC has its own OS 9 module type It is missing the procedure and the RUN to call another passing parameters in the so it is in fact possible for however there are no the compiled form run either by Volume 1 for packed modules invoice q fred and enter a BASIC program without being aware of it C Vu runtime support for BASIC and run your packed procedure for you STYLOGRAPH Stylograph is perhaps best desc Dynacalc it has its roots in OS 9 6809 Color Computer and the Dragon Stylograph is a th insert overwrit little more system When you start St essentially a menu which you move a press lt return gt against one of the options then options include to disk for late call OS 9 r printing printer setup options Selecting edit can move around down and so on insert or overw from system mode puts you in the text If you actually want to ite modes tylograph you a with ribed as a however and escape ST cursor shell edit print read more text medium re presented with wi system mode th the i save text ex th Mg Or Let ty SL scape mod for TIGHE UL
9. language Tt Ut ts Having said CUG UK ar stderr output to the file this library obtained by the source interrupting is a subset of Unix listing the moment no utility is provided to access GEM Furthermo r single density on track 0 te in single density However the Color Compute tware in this format Cumana offer a copying se pipes both un this default can be customised and can be changed a ting between processes DOS dis re the standard OS 9 as if not o rvice r if you named and named pipes a TO Signals and Events These are two more ways of communica familiar Unix mechanism of Signals task COMMANDS command interpreter most of the commands are not built their own right the fact tha to the user n for exampl to change da the shell will terminal bu but it is ver line parame is just another program t despite the claim o lexx or yacc and the e the command to list a ta directory is chd t there is no support ters is built into a limited You do get thr standa y out and and Wild ca using rr respectively so gt gt listing rds are limited to PERFORMANCE Vhilst the system commands for OS 9 were written in system itself was hand coded in assembler that OS 9 does not page memory the performance of an OS 9 system is far b
10. iden EXT ERNAL othe Arra MOV Can Bit 16 bit INT procedur tifiers can contain dir more about the end of line character PASCAL COMPILER ea ment Ss state and US lt ctiv EG YE call fiel STRING data COPY CONCAT ARCSIN ARCCOS Random access to files with rocedures and functions FRIGHT Flow control for both I O and maths er operating system with type with proced and POS d manipulation All portable c As ode these can be disabl Extended heap management Access to command line arguments Seperate compil Listing control ation flags I said conformant arrays will have noticed that there is a new type STRING popular use of conformant arrays is for string p ER and 32 bit TAN and LOG led with a compile time opt LINTEG ER with auto Level 0 compatible this later EL ures ETE INS ERT functions UPDATE R SCAN CAP T FI ELDG the ISO Level 1 feat POSITION GET FILLCHAR MOV ror conditions OS9 procedure ET and FIELDPUT tion ture ar matic coercion from one STR and functions LENGT PUT total however it the Unix function in the OS 9 port of Kermit code have been to change things This means it does not The many extensions to t
11. is the long awaited well by me anyway Laser C from Megamax Inc for the ST The main change between this and previous versions from Megamax is a full featured shell with RAM cache access to all the usual file management routines exception trapping with backtracking with integrated editor very fast scrolling no 32k limit on files Also includes a whole host of utilities all the Unix usuals ls egrep make ar etc including an extendable debugger Libraries are not_ up to the draft ANSI standard although the compiler itself does support enumerated and void types hope for the near future perhaps A full review will appear in the next issue s Simple C Also just received is a new title from David Fulton Publishing entitled Simple C aimed at converts from the BASIC lingo Cost is 11 95 ISBN 1 85346 057 5 Author Ian Sinclair Review in next issue Surcharge Dropped Finally the surcharge for the 3 1 2 disk version of C Vu has been dropped Minix Early Notes By Don Forbes MINIX a contraction of MINIature and unIX What are your expectations Perhaps it will be useful to begin with a description of what you get and then Volume 1 C Vu Issue 3 assess its immediate usefulness The basic system consists of the documentation Operating Systems Design amp Implementation By Andrew S Tanenbaum ISBN 0 13 637331 3 and eight disks 5
12. t all the volumes in the library for next to nothing by writing a review of each volume perhaps with details of any difficulties you encountered if you are porting to a different compiler OS etc NOTE This offer also extends to members you have already had articles published in C Vu Just write in enclosing a blank disk telling us which issue of C Vu your article appeared in an which volume s you would like to receive CUG BULLETIN BOARDS Volume 1 systems Chronosoft Lair V21 23 at present CIX 01 399 5252 Have you Digital Matrix V21 22 Dr Solomon s FIDO N81 The group has some presence on all o If you have a modem to our conference or special interest why not C Vu Issue 3 the following bulletin boards conferencing give them a call and make a contribution 021 744 5561 All speeds r Barclaycard handy 021 705 5187 02403 4946 group 300N81 N81 1200N81 All speeds C Wizard s Programming Reference I am always a lii the ego of the po Advanced Programmers fit into this category In his dedication Mr be a reference card reference books should be operators preprocessor n frames used to make part tential purchaser Guide To being a highly readable and usabl library file I O and a number o By W John Wiley amp Sons ISBN 19 9 Review By Schwade
13. Hixson TN 37343 Telephone 615 842 4600 Telex 510 600 6630 REVIEW OF MIX POWER C By Martin Houston The first issue of C Vu carried the special offer of the MIX C compiler This review concerns the new compiler from MIX POWER C POWER C has much in common with the older MIX C The most striking similarity is the price The POWER C compiler costs just 24 95 including postage amp VAT This puts it in the same budget category as MIX C and Zortec nee Zorland C For the 24 95 what you get is a 670 page paper back manual cum tutorial book a book of this size on C can easily cost 25 on its own and two 360k 5 1 4 or 1 720k 3 1 2 disks containing the Power C compiler PC EXE the Power Linker PCL EXE The disks also contain a selection of standard header files and the C libraries in object form Power C uses the MIX object format as used by MIX C instead of the Microsoft standard OBJ format This is no problem as the PCL linker will produce standard EXE files at the end of it MIX also provides an assembler that will assemble into the MIX object format more of that later So far I have concentrated on similarities between MIX C and Power C Now some of the differences Firstly Power C banishes the main deficiency of MIX C the slow speed of the code compiled with it The original MIX C was a fast compiler but the code produced was not
14. and the different E The system once running est contain various parts of t styles of machine Publisher Prentice Hall International 1 4 360k One of these is for booting he system There are several options for 256k floppy only etc has the kern complete equivalent to Unix System 3 V regarded as one of the best stages in d provided Q What would I use it for el in memory a ram disc tmp and is a ersion 7 This version was widely evelopment The Bourne shell is also Questions Arising A As a very cheap startup and development system for Unix programming Q How good is it A Excellent known bugs are minimal we are collecting these but none to start with Depending on your background Minix will or will not be a culture shock Q How much does it cost E the book and disks This translates as less than 600 for style system on a PC clone The book is of course A Less than 100 for complete working Unix available seperately too Q What is the legal si tuation A To quote the code listings for Minix Copyright C 1987 by Preni Permission is hereby gran educational institutions binary and source parts of individuals and educational educational and research pu the system tice Hall Inc modify and rposes For ted to private individuals and redistribute the to other private
15. attempt to subsequently change it s value will generate a warning from the compiler Unfortunately without proper protection there is nothing to stop an external library function from modifying a constant when passed the address of that constant For example const int p l n libfunc amp p if the library function libfunc modifies the value of p then the problem will never be detected There is no way in C to indicate that a function taking a pointer argument will modify the data to which the pointer points Unless the programmer is careful the use of the above code will cause problems if the constant was placed in ROM or the hardware traps write access to constant storage I would have liked to have seen the use of VOLATILE extended to function declarations to indicate that a function modifies external data through the use of a pointer For example int libfunc volatile int Operators The unary plus operator has now been incorporated into the C language with the same precedence as the unary minus Other than this the set of operators and their associated precedence have not been changed Run Time Library The standard C library has been enhanced with extra functions proposed by ANSI Many of these functions are already available in many compilers most notably Microsoft which has very close association with the ANSI committee Conclusion In these few page
16. compatibility and the current version V2 1 which is provided by Cumana contains most of the features found in Unix INTERNALS There are several concepts built into OS 9 which contribute to it being a Unix like programming environment they also help to explain why OS 9 is not exactly like Unix Memory Management OS 9 manages memory by the use of memory modules No program or constant data Volume 1 can be loaded into memory unless it is in OS 9 s module format a header containing cont roughly and or data One of the pieces of information then a CRC which is used to spo C Vu rol informat that tion t overwrites etc Issue 3 This format is the module contents program t can be taken from the header is the module keeps a directory of all the modules currently loaded into they do not modify themselves ea is not allocated contiguously and the name using this OS 9 memory All modules are re entrant program s data like GEMDOS BSS ar OS 9 s modular system means that it can mak available when multitasking No mat running at the same moment permits two rather nice features of OS 9 The first is the sticky module normal directory whilst it is being run by at least the module is kept in the directory until commands are fast sticky t disk cache The second nice instruction for hand
17. establishments for corporate or professional use permission from Prentice Hall is such permission will be granted subject to a few conditions required In general In general additions wil source code for the co not available from Prentice Hall Transmediair Utrecht Melkweg 3 3721 RG Bilthoven Holland Tel 30 78 18 20 BV mpi J probably be welcome casual abuse will not The constructed using the Amsterdam Compiler Kit is but from Implementation Details This section and th next ar deliberately kept short because it is still very early in the author s understanding of both the system itself and the actual implementation a much smaller and majo The Minix kernel is fundament r subsyst system In relation to the PC IBM PC all This is because the Bios supplied for these machines is not interrupt tally different from a normal Unix kernel It is tems are now implemented as such eg filing XT or clone the Bios is not used at Volume 1 d Obviously this all the devic riven tasks run to compl is not viable in a multi drivers control without a hard di used good news The system should run without For sk is a welcom for 386 systems in if featur Mention has been made of an implement As the scale of this aspect is of interest to you C V
18. file that you lost plus a few more for luck 6 You will find that recover will create a number of files in the current directory in the form flist 0 lt number you wanted gt It is now up to you to piece together your original file from these fragments The only help I can give you for this stage is the observation that flist0 is usualy the first block of the file flistl the second amp so on If any files have been written since your file was deleted then the first few blocks will be missing This is because the fr list is actualy used as a stack The most recentley freed block is the first to be allocated to a new file The file is compiled with the following options cc M2es DM_KERNAL o recover recover c Happy Hunting ATARI ST LATTICE C V3 04 01 BUGS List courtesy of Metacomco plc The following list documents all the bugs found to date in Lattice C version 3 04 01 If you wish to obtain a disk of updates please write to Metacomco at Lattice C Updates Metacomco PLC 26 Portland Square Bristol BS2 8RZ Pleas nclose one double sided disk or two single sided disks if you require all the latest updates or one single sided disk if you only require the updated libraries In the following list a tick or cross indicates whether the bug has been attended to or not a normal bullet usually indicates a partial fix detailed
19. if x jj y kk result nn x jj return result This is not exactly the best way to do the job but it works and can be easily understood Finally we overload the operator again so that it can be used to copy the elements of one set to another Note the differences between the parameters of this function and the previous operator one void intset operator intset z int u Z pos if u gt size abort This can t be happening for int 3j3 0 jj lt u E set jj zljjl The error message is given because it is not possible for the intersection of two sets to be larger than the size of the largest set It is simply included as a catchall if there was a bug in the function to handle the operator Volume 1 Now we will two sets C Vu put this all together in a program that uses and build a third that consists of the intersect the new tion of typ Issue 3 to create the first two set example intset a 4 b 4 c 4 a 12 a 45 a 90 a 16 b 17 b 45 b 16 b 78 c atb Ihen the program enters function SET EXAMPLE the constructor is called three times to allocate space for thr new types Then w nter four elements into the sets using the overloaded assignment operator The following line t
20. it CO get super ly you ar to of others r mounted use e to shut filesystem blocks faster than you can act to st tive user on a machine and top it you logged on for this the deleted fil rrm ks try this program a pr syst fil m system r et If the file was on ve The important thing is tha re mounted until the recovery has to the filesyst It is these to a directory in which it will tem blocks ry blocks From th saving a big file off floppy amp use usr tmp as Invoke recover with the name of th and a number of K byte blocks to dev usr root re repare a system boo the filesys the Jt a CAKSN recove be safe from a boot floppy the work a root loppy tem freel TO place List will r is int create then mount wa In most cases I would agree with you ecious r status quickly the longer loose the data t the machine down fast Make S on then simply take the tc so you can execute th th wil wil I Ce temporary dev u filesystem devic d v root recover from the free then some foresight is he recover progr the lost file mu f ANY files are be taken to writ rested in iles or LSE I I sr from that you discard will iR Volume 1 C Vu Issue 3 This number should be the size of the
21. programmers conferences with guest speakers and exhibitions etc I particularly want to hear from you if you are willing to be considered for a committee post Defining New Data Types In C By Steven W Palmer Volume 1 C Vu C is an object oriented supers Bjarne Stroustrup development more manageable by incorporating data abstraction king and modularity chec it so popular program In this article powerful feature the the programmers control programming language abil while ret With few exceptions I am going to demonst lity to creat This encapulates which is to inc be built up out of individual trate one of C te new data types which are totally under reas t of the C programming language The intention of the language is to mak Issue 3 developed by ram is al t s most the whole philosoph modules crafted by different Standard C comes complete with a number of types hav rs are applied is dec when adding two different code to ry DOUBLI as to is co will and LONG Each how the operato mpiled obvious For example of thes th ase by which t pr built in types CH thei C provides range of new typ type can a F called INTSE then be used y generat the facil m in Lity to generat operators are applied which is r own operator
22. standard utilities to define a file and build a simple enquiry system and report system The second is to write from scratch an entire application system I ll describe the former if you re interested in the latter then I d go and visit your dealer 6h gt oO H The first job of building a sculptor database is to define the layout of its records this is done using a program called describe This presents you with a prompt to define each fields name title for display contents and size and any validation criteria This done a program called newkf is run to initialise the database followed by a program sg which generates and compiles a sage program to allow addition deletion search and amendment of the database You then type sage lt database name gt and you can start entering data into the database To build a report program you simply run a program called rg and this creates a sagerep program in the same fashion as the sg program does for sage MICRO EMACS As part of the deal to get OS 9 cheaply Cumana had to forgo some things that normally come with Professional OS 9 The FSAVE and FRESTORE commands which are the official method of archiving OS 9 hard disks are not included Nor is Microware s port for microEMACS 3 6 instead Cumana have arranged to supply the OS 9 port of microEMACS 3 81 o
23. the same thing The best ays a pie chart on ten that will work terns when the to a video games designer overnight but for an on sc in the pas The Power C Libra An important extra available wit This costs an amazing 10 usual complete and of ly only available for a ve anything that doesn t suit you EXE assembler PCA which library think a great improvement with special macros I have successfully compatible machines and run so is used to assemble I really like the provision of an assembler the short sections of assembly code needed to support is small and simple without any of that it is the only assembler the Power C armed with the real wor ry high price kinds feature of the Compiler is the ability to write rograms using functions from the library without contains an example reen Ga E Doh ry do k of th Power C is the source code for The library source code for other compilers is if at all fers valuable extra documentation and the ability Th Terminate and stay having to resort to clock The program Playing with TSRs is ave been put of by es all the assembler a TSR in easily the libraries r C source is to change e Powe The library sources even come with a simple the low level assembler parts of the PCA is ideal t a high level the co
24. this Allow your mind to wander off down a couple of levels at each step without getting too detailed just to see if things seem to flow OK Think about how you are handling the data What data structures or types are you using How will they be passed from function to function What function needs to know what is that data going to be available at that point in the process For trivial tasks these steps ar asy The more complicated the task the more essential it becomes to do each correctly Having done this on the top level then really the same procedure can be repeated for lower and lower levels Volume Structuring then makes us 1 C Vu The story so far of several key points Issue 3 The program will be constructed on a hierarchical basis with each level overall ower levels Data structures and variable names will be chosen to suit level At the highest level onl E c s Where nesting of loops more than 3 or 4 sub level function to hold onstructs such as for ets of instructions Or restricted to handling tasks and data applicable to that 1 purpose of a level will not be obscured by detail while then consideration will evel The relating to the particular ly broad outline steps will be identifiable ach procedure will follow a single entry single exit patte
25. who ther about C itself or related to files should be a double if using examples maximum size is 6 3 4 by 9 1 4 can also be accepted ete th will not be reproduced in C Vu have members who OS 9 Unix Xenix Mirage TOS text files on 3 1 2 or 5 5 1 4 BBC Micro format standard DFS 100k disks can also be accepted Th to one of the bulletin boards or CR LF between Generally but will although NOTES FROM THE ULTRA CONSERVATIVE RIGHT WING By Marc J Rochkind Here s a list of rule may be violated but only fo rd uded there s to 1 Most standa always be incl although it s the header fil means that mos some of your 2 Never decla declarations lessen t C files will star Files start functions have a 5 The manuals o in discover what reliability rules that every C programmer should follow ra reall y good reason header associated with them or t with 5 with even more re a function if it s declared in a header portability ften fail usr include wherever to 10 includes Don to identify what this header is You might consider grepping headers go with what functions Occasionally a which should This rule t feel weird if as redundant and maintainability discover that some standard functions aren t in any header If you you might consider Volume 1 C Vu Issue 3 codi
26. B FALSE have b such as would be Notice that the strings TRUI and is not just a textual substitution An important feature of the of this is define BUG UG tf some debugging message If you wish to remove the debugging printf from the that needs to be removed is the define DEBUG defined the first pass of the compiler will DEBUG and its matching endif For only one the work involved in placing a comment aro same result but i it is much quicke message unt the p Fh to control them with the macro p With some compile on the command rs it is possible to supply definit ne so the define DI li Unlike comments ifdef endif pairs can be nested n p macro processor is the abil a defined sybmol and alter how code is compiled accordingly as if omit everyt this the program has many debugging messages inst ach reserved Macro processing done with an editor to test the value of The most common use Lity to selectively include extra code for debugging purposes program then the onl the symbol DEBUG thing between an ifd is little different tf statement to get tead of one thing is not y t from the then rini rocessor tions to the macro processor EBUG need not be present in the file itself ndif will match the most recent ifdef
27. I to tag each endif with the ifdef it belongs to to ifdef DEBUG printf some debugging message ndif DEBUG The comments around the second DI there are many ifdef endif pairs in the code it is a good idea save confusion like this EBUG may not be need for all compilers but Volume 1 Microsoft C for one complains about As comments are the first things to comment can be put anywhere without What I have just presented above is code If more use is made of macro easier and neater C Vu Issue 3 extra characters after an endif directive be stripped out by the macro processor a changing the sense of anything P the traditional rocessor features debugging can be made way to include debugging The most powerful feature of the macro processor is that macros are allowed to have paramerets The best way to ex define MAC A B C A B main int vl v2 v3 v2 v3 10 MAC v1 v2 v3 will exand to main int vl v2 v3 v2 v3 10 vl v2 v3 Although the use of macros with is to expand wouldn t value o work as a function v2 v3 The last tool we need to b ain this pI C of befor awar ar special macro names Ther for itself note the doubl underscores on number that the macro processor has got st fdef DEBUG fin DEBUGO S ls defin ndif d
28. PILER is a very useable debugger with suitably brief n of Microware C is included in the upgrade this is the is a full K amp R implementation with one restriction bit and unions are not supported Microware have stated that they intend to implement this in a future release sions have been added enum and some of the functions ly define d to int A full set of termcap access in li i The pr n added The preprocessor directive if xxxx is ne assembler with asm though there is a strong warning eprocessor also supports multiline macros to be position independent the amount of static dat ta that can be referenced is limited by what can be addressed with the index register plus 16 bit displacement mode of the 68000 As a result a new remote class has been added that allows reference to static items outside the initial 64k In reality not ma there is no restiction S torage ny programs need more than 64k of STATIC variables and for automatic or malloc d variables The code produced by the compiler seems relatively efficient unlike the Lattice Compiler the first 2 parameters are passed in the registers There is also an optimiser which improves the code by a claimed 11 in speed and size Volume 1 C Vu Issue 3 Like the K amp R compiler the compiler is split into seperate programs cc executive cpp preprocess
29. Volume 1 C Vu Issue 3 The Journal Of The C Users Group U K EDITORIAL Good grief issue three already This is also the biggest issue so far and if EVERY member of the group made the effort to write something for C Vu we could quite easily get up to a fifty page issue in time for Christmas 1988 that is As usual a big welcome to all new members especially those who DON T own a PC or compatible editorial bias creeping in again If you have an Amiga ST Mac Archimedes or whatever why not write a review of your development software and the operating system environment you use If you are feeling really brave why not try porting some of the source library volumes and tell us what problems you encounter As you are probably aware until now the C Users Group U K has been run on an informal basis with most of the hard work being done by Martin Houston up in Birmingham Now that membership is into three figures it is time to go legit We will be holding the first annual general meeting of the group on Saturday 2nd July provisionally somewhere in the UK but probably Birmingham It really is essential for as many members as possible to make the effort to turn up and hopefully take responsibility for one of the committee posts Further details inside Phil Stubbington Editor STOP PRESS Laser C For The ST Just arrived although too late for this issue
30. achine will not their is no root devic like hierarchial directory st 28 characters ty eight yes though for compatability lic permissions are implemen t damage the file st becaus achd fficient us ter how many times you have a program only one copy of the program is loaded user trap handler r is a module which can be linked by all files and devices ar classes file manager terminals ly fast the cursor keys The f of the memory It also ly a module is only kept in the t one process the memory is needed Most of the is rather like having a large and with sticky modules OS 9 uses the 68000 TRAP 0 the other TRAP numbers are free for user trap a task to by means of a trap call ST this contains the support r conversion routines the trap handler th module to rocessor can t allows the mat on floating point p treated as a within which they have module q v Random Block File printers modems Pipe Unix like pipes and comes with SCF RBF and PIPE There disk BF RBF S GI and Midi ports It provides line ST console driver has been user defineable The keys ar and in monochrome a 50 loppy driver allows you to The hard disk device driver The RAM disk tructure though no links long File access with OS 9 6809 reasons ted Unlike Unix a sudden power tructure One quirk is that vi
31. annot of course publications at a later date accepted on an all rights basis Pl 0 ase regard f somebody C ST and and a combination of Word Perfect the Megamax Laser Editor which isn t Thanks for this issue must go to all Group very word in C Vu as being a trademark or regist Vu is composed entirely on an Atari 1040STf using Timeworks ST Writer those who made the effort U K ad of 3 or U K has Desktop Elite something for it and to Gollner Publishing for the printing more then or of the and may not be reproduced in whole or in part without the on the understanding that the the right prevent you from offering the same article to other but please let us know if the article has been tered trade name Publisher lst Word to write Additional thanks to HiSoft Metacomco Electric Distribution AS amp T and Computer Manuals for taking the flyers at the Atari Show Also to David Eastwood at Sahara and Dave Hurley at Analytical Engines and finally to Rupert Steele for the frequent plugs in Personal Computer World The End Zone Phil Stubbington Editor
32. aps it is worth stating that before you begin any sort of work you must fully understand WHAT you are trying to do and HOW you are going to do it The best structure in the world will do nothing if the algorithm is wrong However if the algorithm is wrong if you ve structured your program well finding and fixing the problem will be a lot less painful m Thinking back to our original problem If we realise late on that our algorithm for opening the lid of the kettle is wrong then we only have to change the detail INSIDE that procedure Where it s called from the body of the program remains the same Structure has helped us We don t need to go through 200 lines of code looking for affected lines a This early stage of thinking of the problem and deciding on the algorithm and then laying out the broad steps is crucial It s the most difficult part of the whole process Get things wrong at this point and you make work for yourself later on I m going to say that again because it s important Get things wrong at the initial algorithm and main body stage and you make work for yourself later on So take the time to think it through Here are some tips to make this easier Just write out steps in plain English first Play what if games with the data input Think about what it will look like or actually do in the end Is what you re planning now going to give
33. ar This rules out functions like atol which reports no error 15 Do not put in gratuitous comments because it cheapens the value of all comments Then the reader gets into the habit of skipping comments and when you have something important to communicate there s no way to do it Also comments make the code harder to scan so they have to be really useful for the reader to want to pay the price Here s an example First a gratuitous comment get input from tape drive if readtape ERROR Now a useful comment can t use gettape hangs system when buffered if readtape ERROR 16 Except for the numbers 1 0 and maybe 1 always use a symbolic constant Do not dimension arrays with numbers like 81 257 etc For string lengths adopt a convention and stick with it I use a symbolic constant to define the length exclusive of the NUL byte and then add one for dimensioning The alternative is of course also OK 17 Every switch statement should have a default case to reduce debugging If it can t ever occur use assert switch x default assert FALSI GI 18 If your compiler supports function prototypes always use them both for library functions and for your own They are the greatest contribution to C programming since the curly brace I ve found this paradigm useful for static functions as it makes modification
34. benchmarks but also a number of general purpose utilities Volume 1 C Vu Issue 3 Unix Utilities 5 some Games 2 the one that applications with parts NEW started it all off the 17 written in lex and yacc Colossal Cave adventure with 21 full source code Software Tools 2 some WHY NOT CONTRIBUTE some of more programmers tools see your own work or conversions volume one and a simple NEW of existing library volumes to 18 Unix Curses type screen other systems Non IBM library 22 specific contributions especially welcome DISCLAIMER The C Users Group U K makes no representations or warranties with respect to the contents of The Source Library listing and specifically disclaims any implied warranties of merchantability or fitness for any particular purpose of the library volumes mentioned herein ORDERING To order any of the volumes in The Source Library simply write down a list of the volumes you require indicating disk type 3 1 2 or 5 1 4 your disks or ours don t forget to actually send them and send it with correct payment a cheque or postal order made payable to C Users Group U K to The Source Library C Users Group U K 36 Whetstone Close Farquhar Road Edgbaston Birmingham B15 2QN CHARGES The fully inclusive charges for each volume are 2 your own 5 1 2 or 3 1 4 disk 3 our 5 1 4
35. ce has to have a name so absolut te paths have the form Volume 1 C Vu Issue 3 lt device gt lt dir gt lt filename gt For example h0O sys termcap is the absolute path to the system termcap database file This could cause difficulties with directories for h files etc However there is a system default drive dd which you can define as a duplicate to be the internal floppy RAM or hard disk where such files are assumed to be kept Needless to say the OS 9 format is not compatible with the GEMDOS format unhappily at am told one is due later this year either all single density o to read or writ ST is unable identical with are equipped existing OS 9 user to provide soft that used by OS 9 PIPES are true Unix like thei size however the opener of a pipe Although SBF and NFM are not supplied by Cumana or their UK Agents Vivaway code both tape streamers and Networking are possible events is semaphores Like Unix the The familiar Unix rag not There is no control cfp command redirection refered to as delete befor ls batch list of commands typed in at the upport for command file processor ugh you can only redirect th tdin Some s tho tel shell prompt belies UNIX in operation and appearance The command set common commands are not the same the command and
36. cessor directives have been added error pragma and lif if has been extended to allow the use of the defined keyword in preference to ifdef error forces it s argument to be written to the user console This allows users to implement their own error checking at compile time For example if a program must not be run with a STACK size of larger than 30000 bytes then if STACK gt 30000 rror STACK too big Truncated undef STACK define STACK 30000 ndif will detect this and inform the user The actual behavior of error in relation to the compiler is mostly compiler dependent at the moment pragma allows options to be passed to the compiler from within the source code The choice of options is manufacturer dependent and will vary between systems As an example Microsoft C V4 0 provides a single pragma to toggle generation of stack checking code pragma check stack causes the compiler to include code to check the stack on entry to subsequently declared functions to ensure that there is enough room for local variables pragma check stack switches off stack checking code The preprocessing rules have been rewritten to remove the ambiguities inherent in the old compilers One notable change is that ANSI now allows the use of a macro name in it s definition Where this occurs the macro name will not be expanded This allows the use of a macro t
37. d real time clock plus several disks how many depends on your disk capacity on which come OS 9 68000 operating system and commands macro assembler debugger C compiler Pascal compiler BASIC pseudo compiler Stylograph a word processing system Dynacalc spreadsheet Sculptor 4GL and database system MicroEMACs Autortc and setime GEMDOS utilities The disks are not copy protected however all but one are in OS 9 format and OS 9 will not run without the cartridge With the package come three A5 ring binders containing the manuals which at four inches thick means you have some reading before you can use all the software There is an optional Technical Reference Manual which is a must for serious ie systems programming I shall cover each piece of software in turn THE OPERATING SYSTEM HISTORY OS 9 68000 is a multi tasking multi user operating system developed for Motorola by Microware Systems from Iowa The original OS 9 was developed for the 6809 processor The design was based on Unix tm it exploited the ability of the 6809 to run re entrant position independent code to give multi tasking in 64K 2M The 64K version was ported onto the Tandy Color Computer and the Dragon where it has developed a loyal band of followers Naturally when the 68000 was announced Microware was commisioned to implement OS 9 for it with the greater processor power and memory further steps were made towards Unix
38. disk or 3 50 our 3 1 2 disk A CALL TO QL OWNERS By Martin Houston I notice from group records that there is a significant number of you out there that use the Sinclair QL either as an only or a secondary machine I have had more than one enquiry from QL owners about how they can access the CUG library as the QL cannot directly understand the MS DOS format disks that the library volumes are supplied on If you are a QL owner that can access the CUG library by whatever devious means you can devise why not help out your less fortunate fellows Why not become a SUB LIBRARIAN and offer selected library material to other QL owners on microdrive or native QL disk format If you would like to take on this responsibility then drop a line to Martin or Volume 1 C Vu Issue 3 Phil and the library sub branch will be publicised in the next issue of the newsletter The sam diffe call Sirius Lib formats ra If you want from the lib library fees expect to get As you can see by flicking through any issue of C Vu on a small group of members who make the effo what a user group is all about all idea goes for anybody else who can o rent means than the central library source can provide for all those exotic old CP M formats How about an Appl rian to offer th vice of ser to be a sub librarian all that is yours to keep as an incent rich by it though rary in t
39. e complete sources including a number of utilities but not the C compiler sources details of how to obtain these are mentioned elsewhere in this article Can be used with 512k but program sizes will have to be adjusted ISBN 0 13 583873 8 a set of diskettes for 256k IBM PCs As above but the C compiler executable is not included ISBN 0 13 583881 9 a set of diskettes for 512k IBM PC ATs Supplied on 1 2M disks otherwise identical to version for 640k PC except RAM disk is slightly smaller ISBN 0 13 583865 7 a nine track industry standard 1600 bpi magnetic tape in Unix tar format Contains all the sources an IBM PC simulator libraries and programs to enable the file system to work on the VAX or other Unix minis Ports to other systems should not be too difficult as the file system and test programs are in C ISBN 0 13 583899 1 Any correspondence regarding Minix should be addressed to Don who has kindly offered to be the official Minix coordinator within the group Don Forbes 35 Upland Road South Croydon Surrey CR2 6RI GI Volume 1 C Vu Issue 3 Tel O1 688 5794 The ANSI Standard For C A summary of the proposed ANSI extensions to the C Programming Language By Steven W Palmer Introduction Since it s introduction in 1972 by Dennis Ritchie at Bell Laboratories C has matured over the years with each new implementation A number of features designed to provide the language with stric
40. e identifier is subject to external changes and must not be changed by the p N timiser SIGNED is already present in most compilers and complements P C it O UNSIGNED Volume 1 C Vu Issue 3 Escape Codes The standard set of character codes is extended with a for the BELL character and v for the VERTICAL TAB character Numeric escape codes now support hexadecimal codes in the format xnn or Xnn where nn is a two digit hexadecimal number Both of these extensions are already implemented in most modern C compilers The use of an escape character followed by a newline to indicate line continuance was originally restricted to macro definitions and strings ANSI now allows it to apply to any line of C source code Strings Strings may be concatenated by following the terminating quote of one string with the initial quote of another and with only whitespace in between For example puts This is a very long string that has to be split over two lines to fit can now be written puts This is a very long string that has to be split over two lines to fit The decision as to whether similar constant strings share the same storage space has not been resolved although it is still considered bad practice to modify string constants Microsoft C V5 0 supports string concatenation Preprocessor The following prepro
41. e the two objects after all macro expansion has been performed For example define gencode x callgen x If the following is encountered in the source code gencode 12 it will be preprocessed to callgenl2 Numeric Constants The single type modifier letter L or l which was used to cast an integer to a long integer is now complemented by U and F U can be used with any integral constant and casts the type to unsigned It may be used in conjunction with the long integer modifier letter Volume 1 C Vu Issue 3 F can only be used with floating point values and changes the default type of a floating point number from double to float A floating point literal is always assumed to be of type double by the compile ry T However the proper use of function prototypes eliminates the need to use a type modifier at all Where needed a cast is more explicit The type LONG FLOAT is no longer supported An additional type LONG DOUBL has been introduced It s range is implementation defined but should be the same as or longer than DOUBLE GI Generic Type The type VOID has been included as a generic type which can be cast to any other valid C type For example char malloc unsigned int has now been replaced by void malloc unsigned int The size of VOID is virtual so the use of SIZEOF with VOID has no defined mean
42. ecify our own means although most users stick to the conventional approach of allocating space for the type on entry and destroying the space on exit It would probably be easier if I illustrated this I am going to create the new type INTSET which is simply a set of integers The C code to do this is as follows Define class INTSET class intset int set int size public intset int intset int int amp operator int void operator intset amp int amp operator intset intset int amp operator intset intset hi Note The symbol denotes tha The class enscapulates all the dat INTSET All definitions before ta and the PUI the rest of the line is a comment functions required to manipulate type BLIC keyword are private to the class and Volume 1 C Vu Issue 3 cannot be accessed by the user without explicitly qualifying the class name In normal use the user never needs access to private data and functions The public class contains in order the names of functions to create the new type destroy it access one member of the set using the standard C subscription format which has been overloaded here assign an element to a set compute the intersection and to compute the disjoint of two sets As we develop the type we can easily add extra features For example we can allow all the elements of one set to be copied to another b
43. es format comments t of the hazards For example the and explains why you should declare variables which it is obvious that one of the aims is to references are made to the such as the EOF out ting style and extensive use of diagrams rations for example actually adds t being space fillers As a pleasant so if you can t the index usual spot what you are ly helps ly proficient C backup to a tutorial guide for newcomers to a similar style has been adopted for other books for P rolog and Modula 2 I think Debugging With The Macro Processor By Martin Houston The C macro processor is the first pass of the compiler that converts define C Vu Volume 1 symbols into the data in their definitions y E defin defin TRU FALS CJ main G py if TRUE printf TRUE else if FALSE printf FALSI F py es This code is just a bit of nonsense to show how the is how it would look after the macro expansion pass main if 1 printf TRU else if 0 printf FALSI i TRUE has been replaced value is false to C The action that Notice by 1 and FALSE of y E has this program is Issue 3 An example of this is macro processor works Here of the C compiler a zero y Eis been replaced by 0 to print the word TRU pu
44. etter than a Unix system running on the same machine LGA not execute files as though fo utility called I O rd I O paths They are append to and appends the and to some Unix like commands are available from the and you could port a Unix shell to OS 9 with ALL its features ks though I formats are you may be aware the the format used is r and Dragon so many OS 9 suppliers re an re available r is a slight difference from Unix in that they are by default only 90 bytes any size by you can buy them from Microware and provided you are willing to resort to machine are the The nearest equivalent to In fact t into the shell but are seperate programs in it is very similar to this is most certainly NOT names of the directory is ean they were a r flow ror the actual operating As a consequence of this and the fact infact Unix wouldn t run ona Volume 1 C Vu floppy on system as OS 9 does MACRO ASSEMBLER LINKER DEBUGGER This is a competent conditional macro assembler support ATV s format q v ASSEMBLER though as is usual it doesn t Issue 3 Two special directives PSECT and VSECT are supported so that the assembler can generate files suitable for the linker to build into OS 9 module LINKER A linker it doesn t require you to write a control file first as does the GST Also its documentation has the decency to tell you the le so i
45. f you really wanted you could write your own stem The g option causes a symbol table module to be generated as well as the output module this is used by the debugger Linker under GEMDOS format of the input fi linker for a target sy USER STATE DEBUGGER This is called the user state debugger because Microware also have the system the difference is that the user state debugger is for normal state debugger programs and all system state debugger is other operations carry on in the background as usual for input so does th The user state debugger al commands current version supported so is in the manual Because OS 9 code has functions have al time All this happens withou the operating system s suppor there is no macro facility it The OS 9 implementatio The C Fields within structs Some of the ANSI exten though void is current lso b The for developing system code and when this debugger waits whole system Llows debugging of a program with providing the symbol table module is available access to all the global variables Not only can you set breakpoints and change memory values you are able to trace execution seeing each instruction as it executes or execute a number of instructions at a for a process running in a debug state the rest of the system being affected because of Whilst C COM
46. further in the text SRAND and DRAND do not work V CXM33 and some FP primitives corrupt registers This is a serious bug as it has a knock on effect on other functions Y LINEA H contains 4 bugs e FORK and EXEC contain bugs As a workround use PEXEC instead as this is called by both FORK and EXEC PARTIALLY x PUTENV often returns wrong results x STCI_H not included in CLIB as stated in the User Manual However STCH_L is equivalent to STCH I STCI_H is equivalent to STCL_H and STCI_O is equivalent to STCL_O STCO_I and STCO_L are equivalents and neither exist in the Lattice library x LINEAC uses A6 Should use A2 e OBJC_ EDIT tree object char amp index type should be OBJC_EDIT tree object char index type amp newindex Volume 1 C Vu Issue 3 This function was documented correctly but was not changed on the disk e FCLOSEALL should be used as FCLOSEAL x There appears to be a bug in the implementation of the STDERR stream Output to this stream will not produce the required effect Y It is not possible to compile to or from the RAM disk using LC TTP This works fine when using LCl and LC2 separately x Problem with STRNCPY x ACCESS returns 0 correctly when mode is set to 0 but always returns 1 when mode is set to 2 4 or 6 x STRNICMP does not seem to work x CSCANF does not operate correctly fo
47. he Dollar sign to the VRITI GI and READ EFT and EL like argc and argv if you wish to produce not supported but you the most In my rocessing xperience Volume 1 OS 9 68000 BASIC is the 68000 descendant of the 6809 BASICO9 BASIC led structured pseudo compi The editor is a simple lin BASIC environment from where you can edit based editor almost C Vu BASIC The BASIC command changes are made by c from to ither deleting th command The edit run and debug identical Issue 3 It is a highly takes you into a complete BASIC programs to the BASICO9 editor ntire lin tor is infact the weakest though once the line is flags any syntax errors nt Once you ve typed in your program you type second phase of compilation is carried out This the program Any runtime e none exist you can run debugger single or run the t This allows you multi step and race mode beneath it It is infact As I said available a re FOR TO sy ST HILE xxx zal Pres NDWHILI A and xxx THEN E EAT UNTIL SENES TIF xxxx THEN OOP SE AHS ty EP O mi l E Zax O OH END Al nu nu 1 mbers mbers User defined types ar TYPE person gender BOO name EAN
48. he usual way and pass central library so that they can be shared the libra t I requi any imp by all tive for running the WRITING FOR C Vu By Phil Stubbington Et rt to contribute v ffer access to the library by Is there still any le Librarian or a ry to people with those re is that you get the volumes rovements back up to the Any money that you charge in service Don t the group relies heavily which is after ry member made th ffort to write _something for C Vu then we would have enough material for many issues to come Although articles are always wel can help out wi th your technical LCOME within i queries the operating system environment you are using At present w can help out with technical que MENER SS 30 including GEM Submissions for C Vu should be in PAM or ADFS standard MS PC G single sided EMDOS format alte rnative is to senda single density rticles by modem ries on MS DOS disks ie conferencing systems Ideally speaking be pl Any graphics should be printed out standard GEM format the only for paragraphs and between each line of source code of great leng aced in the Source Library mentioned mat files IMG or lsewher ting in text code the form of ASCII in this issue GEM types the group we have many members
49. hen computes the intersection of the two sets and stores the result in a third Since the result of the intersection was a set rather than an integer the compiler used the second assignment function instead of the first This concludes my introduction to the C programming language Unfortunately as of the time of writing there are few C translators on the market Zorland is rumoured to be bringing out a budget C compiler as opposed to a translator Such a compiler would translate the C source code directly into machine code rather than into C source cod The resulting machine code will be far more efficient and compact Hopefully when this happens we will s C begin to achieve th ven greater recognition that it is deserved tw IMPOSSIBLE ry E If the system is working hard end up in someon lses File Recovery Under Xenix By Martin Houston I hear you fil cry then th If however you are the only aci program or document that you have been working on for wee before fully enjoying a nervous breakdown 1 If you a this part Once root type sure you have th Your nexi agr re not already root takes to more li sync etc haltsys ment t action depends on which fil Ke it was on dev usr or anothe machine single user In this case recover must be living in bin o thout mounting usr needed you have to p wi on not be written them int Cd
50. ing Initialisation Unions may be initialised The value assigned to the union must be the same typ as the first member of the union For example union long Vid_IO Ptr char VidPtr VidMap 0xb8000000 Volatile VOLATILE is a new type specifier that is really only of interest to the optimiser It specifies that the object it declares is volatile In other words it s value may be changed by an external event during program execution For example volatile int i set_vsync amp i wait_vsync Synchronise with first VSYNC I OF while i Do odd jobs while waiting for vertical sync scan_keyb check comm In the above code taken from an actual program the optimiser would detect that identifier i was not altered inside the loop body and would optimise out remove the body of the loop The use of VOLATILE warns it that the identifier is modified by forces outside the programs control Constants The introduction of the CONST keyword is hoped to reduce the use of define to Volume 1 C Vu Issue 3 denote constant values in a program The use of CONST in place of define is preferred as it conveys far more information to the compiler about the programmers intentions Including CONST in a declaration specifies that the identifier does not and should not change value during program execution A constant must be initialised at declaration Any
51. is necessary because many users have these shells Volume 1 C Vu Issue 3 KRSC V1 1 e Not compatible with MEGA TOS V1 09 Lattice now distribute V1 2 ED PRG e Block handling causes crashes e Does not check if a disk is full It simply writes as much as possible to the disk and then exits resulting in incomplete files being sacved to disk If there is very little or no room at all when it tries to save to disk all of the file can be lost e Scrolling too fast using the UP and DOWN arrow keys can cause a crash DEBUG e Bug that causes the error message BUS ERROR CXINIT A patch is provided Now fixed in V1 04 e Not enough workspace for some applications Use option as a workaround E g 6150000 to grab 150K Fixed in V1 04 e Does not allow LINE A opcodes to be executed in trace mode they are reported as illegal instructions e Gets confused between label function names and it s own command words e Wrongly disassembled MOVE L 64 D1 as MOVEQ L 64 D1 MAKE PRG e Does not work with write protection on MIRAGE UPDATE By Phil Stubbington Following on from my review of the Atari ST version of Mirage in the last issue I have received a copy of SoftWord the house journal of Sahara Software As well as news of a new revision of the Mirage system software it contains several other items which may be of interest to members contemplating switching to Mirage
52. leaving fa ral tec converting programs up library functions used in both manuals robl The Optimiser is part of program like Zort S more compatible TSR writing and maths things from the CUG sou n ems with othe The Power C compiler is ifdef of undef in for I got Power C comes with sample programs to demonstrate of these is a simple program that asks MIX C and vastly e some of the the compiler and not a separate stri This stopped a few things compil the code improve as the POWER C libraries are functions a th ES caught out with the settime In MIX C this function just things the correct rt may not turn you int than adequate for business graphics of all TO way and uses an arg from MIX C it is a good idea to cross check to see if they still the graphics library for values and displ libraries allow programs EGA and even the new VGA screens use colours for colour screens and resor to be writ The Piechart program will t to cross hatch pat extra r C compiler than MIX C was to ANSI standards and the libraries provide many of the ft and Turbo C compilers offer plus numerous useful rce code library and ct about re defined Ing frrst It will also take eir execution speed now ANSI different form what function which ok a string with the ument of all the do
53. lers allow access An example of this is the code for all CN Of course this saves memory be changed without recompiling code be used with Like Unix OS 9 has a uni stream of bytes similar function are manager Sequential each c SCF Sequential Block Fil modules and as such it feature is the its system calls A user trap handle to commonly used ma the common floating point and characte and Pascal compilers optionally generate code which uses this tantly it so an add the change of just one module fied i o system OS 9 divides devices into lass is managed by a five file managers available from Microware Charact functions called th module on the but more import I O r Fil lastly NFM SCF is used for the SI editing one line retrieval writtem for alpha onl the mouse can be enab line mode is availab led e RBF is used for f define step rat uses mult LOPPY Tap Network File Manager console y and is consequen it behaves as hard and RAM dis and a variable sized RAM cache tiple sector transfer to get speed as opposed to a cache streamers The tc Upgrade rinter The RS232 p XON XOFF etc r KS can be configured to be from 64 to 512k Disks have a Unix filenames can be up to twen control is similar to Unix only group and publ down of the m
54. mplex structuring required by MASM that a C programmer is likely to need and is on MIX s original policy of making you use Microsoft then converting OBJ to MIX with the MIX utili POW ly suited to language It I MASM ty compiler an Apricot PC as well as IBM the library sources ER C is suitable for Volume 1 C Vu Issue 3 Apricots and any other non clones as most of the library function of IBM machines could be reproduced and even improved upon The Apricot PC for example has 800x400 video and a sophisticated by PC standards sound chip so those areas of the Power C library could be re written to use the features of the Apricot BIOS to good effect The only problem with Power C for non IBM clones is that the Power C Trace debugger would not be usable For those of you interested in financial applications a BCD Business math library is available for a further 10 This allows calculations to take place without the rounding errors associated with the normal floating point system I see POWER C as an ideal compiler for the serious home user and part time software developer The library is good enough to write serious fast executing software with NO royalty on compiled programs It is not in absolute terms as fast or comprehensive as a top range commercial development compiler like Microsoft C 5 but at 25 plus 10 for the library sources and assembler it offers very good value for mo
55. n a public domain disk with the Upgrade This is I am told far superior to the 3 6 based version supplied by Microware MicroEMACS is a very powerful full screen editor Commands can be bound to the keys of your choice and a macro language is available Multiple files can be edited at once and multiple views of the same or different files can be on the screen at the same time all are edited and kept synchronised MicroEMACS also uses the termcap file so it is possible to use it to edit in both 50 line and the 40 column modes I am very impressed with this editor AUTORTC AND SETIME These are two utilities which run under GEMDOS The first sets the GEMDOS clocks from the real time clock RTC and is designed to be put in the auto folder of the GEMDOS boot disk The second is a TTP command which allows you to set the RTC from either a command line or the GEMDOS clock or to set the GEMDOS clock from the RTC GI SUMMARY OS 9 68000 with all the associated software is a very powerful package You would easily pay 50 100 pounds for an equivalent to each piece of software running under GEMDOS However at the new price of 497 95 inc VAT U K Sterling I expect a lot of people to be frightened off The obvious competition is the Mirage Operating System from Sahara however if you were to add the price of the Mirage OS the BASIC Assembler C and Pascal f
56. ney indeed when compared with the 400 plus needed to buy a full Microsoft C 5 system MW Fi POWER C is available from ANALYTICAL ENGINES Ltd P O BOX 35 EASTLEIGH HAMPSHIR SO5 5WU GI In the next issue I shall be reviewing POWER CTrace the debugger that goes with Power C to enable the quick and painless debugging of Power C programs FIRST CUG UK A G M By Martin Houston Up until now the CUG has been run informally by myself with the help of other members from time to time As membership has grown so much in the past six months the time has come to organise the group on a more formal basis with an elected committee I have set a provisional date for the first as Saturday 2nd of July 1988 The venue fo but will probably be in Birmingham annual general meeting of the group the meeting has yet to be arranged K ct The meeting will probably take up a couple of hours on Saturday afternoon If you wish to attend the meeting then please write to me NOW so that I can get an idea of the number of people wishing to attend for the booking of a suitable venue I will reply to everyone wishing to attend nearer the date giving full details of the venue and programme The AGM will be a chance to meet your fellow group members face to face This time no special events are planned but future AGMs could become full C
57. ng a header so you can just include it all the time 3 Always declare the return value of a function when the function is defined even if it s int This makes your intent clear It also avoids letting a function default to int when it should have been declared void 4 For functions internal to a file and therefore not declared in a header order them so that redundant declarations aren t necessary 1 That is order them as a Pascal program would be with main at the end Only in the case of mutual recursion is this impossible 5 Always call exit 0 at the end of main 6 Make all variables and functions static unless they ar xternal to the file This helps the reader by indicating the locality of the object and it also avoids name clashes in the linker 7 Don t use int 0 and 1 for Boolean operations as these are needlessly general Instead use these typedef int BOOLEAN define FAL define TRUE 1 8 Where a logical expression is required if while etc do not write an integer expression That is do this if p 0 not this if p This is done to speed up debugging When the second technique is used mistakes are often made because the negation of the correct expression is accidentally written This bug is perhaps most frequent with non intuitive return values such as the one from strcmp
58. o it is only any ts but the good for printing range of DEBUG macros that will accept a printf format string and two variable items to print Volume 1 EBUG3 S X Y printf LIN T E yr printf Ss A good convention is to end the name of the expects Issue 3 macro with the number of argumets it Another common way of debugging is to put an if statement around the printf so that the message is only printed if a condition is true This can also be catered for neatly as a simple macro just a variant of the DEBUG macro set discussed above Here is a the DEBUG3 macro with an added if part IFDEBUG3 C S X Yy if C printf Ss d FILE LINE printf S X Y The message is only printed if condition C is true C can be anything that would be legal in an if statement IFDEBUUG3 x gt 10 amp amp y gt 20 x is Sd and y is d n x y Sensible use of macros can do much to make C programming easier to do and C programs easier to read If debugs only tak lin inst on they detract much less from the readability of the underlying program COPYRIGHT amp THINGS All material in C Vu is C Copyright 1988 C Users Group individual authors written consent thereof Any articles in C Vu are published in good faith author has all rights over it and that the C Users to publish it We c
59. o replace or redefine an existing function or macro For example Volume 1 C Vu Issue 3 define sqrt x x lt 0 0 sqrt x Here if the sqrt macro is passed a negative value then it will implicitly return 0 otherwise it will call the actual sqrt function Predefined Macros ANSI specifies that the following macros are predefined __ LINE _ The current source code line number PILE _ The source code file nam _ DATE _ The date at the time the macro was translated in the form mmm dd yyyy TIME The time when the macro was translated in the form hh mm ss STDC A predefined macro with a non zero value Stringization Stringization and token pasting described in the next section are already supported by Microsoft C V5 0 and later versions ANSI allows macro arguments to be converted to strings in the expansion by prefixing the argument name in the definition by the single character For example define ASSERT n 1l puts Error n in line 1 ASSERT 90 LINE expands to assuming LINE is 100 GI puts Error 90 in line 100 which after string concatenation is equivalent to puts Error 90 in line 100 Token Pasting Token pasting is the merging of two disjoint tokens in the definition to create a single new token The inclusion of between two objects forces the preprocessor to combin
60. or c68 compiler 068 optimiser and then the assembler and linker are called Make is also included and the system is a great improvement on the GEM environment for C development the C it is not implemented in OS to be fixed rectory access mode One of the claims made for OS 9 is that it is compatible with Unix at source code level Having ported Unix C Kermit to OS 9 I can say tha as compatible as you might expect The following had to be changed or added for C Kermit All stat amp ioctl calls and the associated settings had to be changed There is no fork call in OS 9 though it can be emulated using the OS 9 equivalent of execve The mode values for open etc have different numeric values There are different valid characters in filenames signal had to be emulated as there is normally only one signal vector in OS 9 alarm had to b mulated the system call is not yet Os n r 0x0d in OS 9 so some case statements had access fails for an existing directory unless the di bit is passed You might get the impression that Unix compatibility is not has been possible to emulate all the non system dependent m The only changes to The Pascal compiler is completely ISO support confor ISO standa like the defin OTH ERWISE F mant arrays rd are listed below selector on CAS of
61. r input of floating point variables x PRINTF Sg Sw Sle formats not working correctly x The escape character f is not recognised correctly x FDATIME Problem with parameter passing and the size of INT x Calling a function containing gt 32K of code will compile OK but gives 4 bombs when executing x Problem with pointers to SHORT INT x and Operator priorities wrong should be higher than x Problems with POSERR V Calls with explicit references to STDOUT treat it as buffered and untranslated x Writing and reading a long constant causes an error x VS CLIP not working correctly Other bugs have been found with the other utilities sold with the compiler These are as follows LINKER e The error at the end of linking that causes the bombs usually occurs when using the DEBUG and NOLIST options together Sometimes this will happen when using only the DEBUG option This is because in the final stages after the actual linking has been completed information is being written back to the wrong ddress It is not a serious error as the resultant PRG file is executable In most cases you can continue without having to reset e Pass 2 of the linker terminates and returns to the desktop too quickly to read error messages when using it from the desktop e Does not recognise PATHS in it s control file e Will not operate with Mark Williams or Beckemeyer shells This
62. rer meni The book now runs to over 200 pages th sect wil and stat David Schwaderer TAC 0 471 82641 3 5 US Import Phil Stubbington tle wary of any computer book which seems to be trying to boost I m sure you know the sort of thing The A The Wizard s Reference fortunately doesn t C referenc tions that this book was only supposed to spiral bound as ALL tions devoted to a C language overview C referenc standard and non standard ment The book has been designed as a quic ticular areas area then has a discussion of the subject reference followed oft discussion of the may contain EOF as an rom the blurb on raft ANSI X3J11 standa 5 Qa phj M Schwaderer has a ve to show the format of something to the book change m chart int the bac elp create portable prog The Wizard s guide is well ten CYPe 1 by a list rams are pointed worth a programmer the language and is probabl Incidentall from Wiley including a ly a useful Yr reference k of the back Throughout the book rd and potential portability problems roblem mentioned above ry readable writ structure decla rather than just the book also has a good index looking for from just flicking through look by any reasonab r appendices k reference guide with white on black stand out as you flip through Each use exampl
63. rn Loop will be used to provide repeated the number of instructions within a loop is be given to creating a further these instructions In this way the broad purpose of the loop is not obscured by heavily detailed loop bodies Functions will Cc 0 P be laid out t on the page in such a way that the use of omments headings indentation and whitespace make the level and purpose f the function clear rocedures will be constructi manner such that changes O r data does not substantially affect program layout ted as far as possible in a general purpose to the boundary conditions number of iterations Next time we ll consider how the choice of data type can help us in structuring THE SOURCE LIBRARY The Source Library is intended to be a collection of public domain C source code brought can use improve 1 Software Tools 1 variations upon the execution system with all sou documentation anda adventure Also cont Life bracket and comment checkers structure analysers three XREF theme several hex loaders and dumpers time command Games 1 principally the AdvSys adventure writing rces sample tains the Towers Of Hanoi and Conways a try disk contains the tutorial Most of volume 10 together so that any member of the C Users Group U K
64. rom Sahara you would be paying 546 29 inc VAT In this light the OS 9 price is good and perhaps if you want and will use all the rolled in software then you should consider it certainly there is more function in OS 9 Volume 1 C Vu Issue 3 At the introductory price of 299 00 excl VAT it was unbeatable at the current price the question remains whether people will really believe that they want ALL the software and the limited Unix compatiblity Given that as with Mirage OS 9 is best suited to a hard disk system Unix freaks should perhaps consider a PC compatible and Minix soon to be available on the ST as well ED though I doubt whether it would be as reliabl ct ct Contacts Microware the writers of OS 9 can be contacted at Microware Systems Corporation 1900 NW 114 Start Des Moines Iowa 50322 Telephone 515 224 1929 Telex 910 520 2535 FAX 515 224 1352 The Soft Centre the UK agent can be contacted at Software House Burr Start Luton Beds LU2 OHN Telephone 0582 405511 Telex 825115 Ref Vivaway FAX 0582 456521 Cumana who are handling the ST version are at Pines Trading Estate Broad Steet Guildford Surrey GU3 3BG Telephone 0483 503121 Telex 859380 FAX 0483 503326 A useful publication if you are interested in Motorola systems in general and OS 9 in particular is 68 Micro Journal Computer Publishing Center 5900 Cassandra Smith Road PO BOX 849
65. s I have attempted to outline the major extensions provided by the proposed ANSI C Standard At the time of writing the standard has still not appeared and is not expected to for many more months However looking at the range of extensions supplied with the new Microsoft C V5 0 it would probably be safe to assume that all these extensions will appear in the final standard with little or no change A more complete coverage of the proposals is given in the standard C reference manual for all serious C programmers C A Reference Manual Samuel P Harbison Guy L Steele Prentice Hall Software Series Second Edition The book costs over 20 but is very good value for money Make sure that you get the second edition Volume 1 C Vu Issue 3 The OS 9 68000 tm Upgrade for the Atari ST tm By Andrew Lindley INTODUCTION To follow up their OS 9 68000 Upgrade for the BBC Cumana have brought out the OS 9 68000 V2 1 Upgrade for the Atari ST Like Swifte s Mirage Operating System it provides multi tasking on the Atari ST and Mega ST without graphics ED GKS Level Oa is currently available for OS 9 and Level 2c is in the works The Mirage standard terminal driver has some limited support for line graphics Unlike Mirage OS 9 comes as an all in one package however this means a larger initial cost The package includes a cartridge with a boot ROM an
66. s ided by the compile floating point numb that used to add tw n operator to create th union of int two sets and the rs ope tion of rator to ct to the new a data struct the same way as the two sets w types and to specif types For example ture of a set of built in types the operat te the disjoint o creat larg scale program increased type taining the low level features of C that made any valid C prog so a valid C widely used and y of the C a large program can ogrammers AR INT FLOAT and the decision r when the program ers the compiler o integers y how the normal we can create a integers This new You can use the or to create the f two sets Because the operator is already used to add two numbers we will have to OVERLOAD it to indicate that it will be used for another purpose This is another aspect of C the facility to redefine the behaviour of existing operators The compiler differentiates between different uses of the operator by looking at the type of the operands Finally we need to define how the new types are created and destroyed When a type is declared locally in a block it is automatically created on entry to the block and destroyed on exit With the built in types this is performed by the compiler C allows us to sp
67. s easier static BOOLEAN fcen int float static BOOLEAN fcn count val int count float val Note that come compilers are set up to ignore library prototypes by default For example with Microsoft C you have to define the symbol LINT ARGS Volume 1 C Vu Issue 3 19 Find out what compiler options generate the most warnings and the strictest error checking and turn them on Make sure all of your files compile with no warnings at all or else you ll miss a new warning because it s mixed in with the old ones Doing this will often mean that you ll use lots of casts But don t just blindly put in a cast to make a warning go away or you might overlook an actual bug 20 How you lay out your programs is a matter of personal preference But at least be consistent or you risk telling the reader that you don t know wha you re doing Either put a statement on the same line as the if or on the ct ct next line but don t do it sometimes one way and sometimes the other Put blanks between a function name and the left parenthesis or don t but always do it the same way Since all bugs are introduced during text editing that s when you need a consistent style So don t use a C beautifier unless it s to fix up a program someon lse gave you 21 Call assert as often as you have the energy to Don t define NDEBUG to remove asser
68. ter type checking and to cater for the increasing sophistication of the underlying hardware hav volved from different companies in different formats The new proposed ANSI standard attempts to bring together the more popular and versatile extensions with a totally revised reference manual which removes many of the ambiguities of the early one This article looks briefly at each of the new ANSI extensions Trigraphs To cater for systems supporting only the ISO 646 1083 character set which provides only a sub set of the full ASCII character set ANSI allows the unsupported characters to be represented by trigraphs A trigraph is two consecutive question marks followed by a representable character The proposed trigraphs are shown below Trigraph Character The new escape code has been provided to prevent strings that resemble trigraphs from being expanded For example puts The trigraph of is without the escape character the would be converted to Reserved Words The keywords ASM FORTRAN and ENTRY are no longer reserved although ASM is reserved in the C reference manual and may later be re introduced back into The keywords CONST VOLATILE and SIGNED have been introduced CONST is a ype modifier that indicates that the identifier has read only properties i e t may not be assigned a value after initialisation VOLATILE specifies that h
69. tions when undiscovered bugs have the profiler tells you your program is ready for delivery because that s when their worst consequences Remove assertions only when that you must Mare J Rochkind February 7 1987 CompuServe 75765 1233 Copyright 1987 Advanced Programming Institute Ltd May be freely reproduced and distributed but only in its entirety with no editing whatsoever except that misspellings may have the marking sic inserted after them like thas sic The author s name and this Copyright notice must be included Every issue of C Vu so THE SPECIAL OFFER FREE LIBRARY VOLUMES far has carried a special offer of some sort and this is no exception We are offering you the chance to receive volumes from the Source Library detail cost d elsewhere in this issue at no cost well almost no All you have to do is submit an article review or letter for publication in C Vu The only rules tha For C Vu are t apply in addition to the guidelines set out in Writing each submission must be on a seperate disk either 5 1 4 or 3 1 2 the minimum lengi th is 500 words If your article appears in a subsequent issue of C Vu you will receive the library volume s of your choice Each accepted submission entitles you to one volume so if you writ You could in fact ge te a five part series you can receive five volumes
70. u too much the memo r an AT tasking their hardware directly screen trouble on an ordina ry management facilit and quite reasonable multi tasking with inter tas far as is known this is not ry IBM ties of Issue 3 letion even if the rest of the system is hanging multi user environment Hence floppy etc PC with or the 286 are k protection no special development has been made Please writ tation for the Atari ST t yet properly assessed but details are not yet known Please also write in if your interest is in real time systems as well as Unix or others the IEEE Posix standard is becoming a reality and I consider the development of code in relation to this the highest priority at present There are also some major implications for the Intel RMK 386 Finally A realistic note getting this system running on your PC may take quite a while and does require a degr of commitment Particularly at present hard disk interfaces are regarded as difficult Do please try and report difficulties and solutions as you encounter them Good Luck Availability Minix is available in a number of forms a set of diskettes for the IBM PC set of diskettes for the IBM PC or true compatible with 640k RAM Consists of the bootable system and th
71. unlike an array an INTSET is one dimensional Notice how we have added array bounds checking to our new type In other languages Pascal Ada or BASIC the processor will output an error and stop if Volume 1 C Vu Issue 3 we attempt to access outside the declared range of an array C did not provide this and consequently lead to some hard to find bugs Often programs would write data all the way through memory until stopped by a reset or the memory management unit Assigning elements to a set is best done like this intset myset myset 12 The number 12 then becomes a member of intset There is no point in using the subscription operator since the actual position of an element in a set if of no interest The code to assign elements to a set is as follows void intset operator intset amp element if pos size abort Set overflow set post element Next we overload the operator so that it will compute the intersection of two set operands The result of the computation is held in allocated memory since we cannot be sure what is going to be done with it The user may either assign or compare it with another set intset operator intset x intset y int xl X pos int yi y pos int nn 0 Allocate enough space to hold the largest set intset result max xi yi for int jj 0 j345 lt xi 33 for int kk 0 kk lt yi kk
72. very efficient and therefore ran much slower than code produced by more painstaking but therefore slower systems like Zortec C The new Power C compiler is still fast but can now produce respectably fast object code as well Volume 1 I compiled the dhrystone benchmark program capabilities of a compiler or a machine under Power C and it gave a very similar program C Vu a well to execute a Issue 3 established test of the typical application dhrystones per second rating as a Microsoft C 4 compiled version of the same program All Power C programs are optimised cost Secondly Power C is The compiler conforms Microso tensions for graphics functions that ex I macros and t time but is A word of wa standard and they used to do sets the MS DOS time in it but type struct Mic Vhen the screen on CGA Hercules screen is mono The graphics suppo it is more Another fun resident p assembler The manual compiles down to about 3k so TSRs are quite possible in lways interested me but ll in assembler something that understandable C tried compiling seve xperienced very few p reats one as an error easily fixed by an programs originally written rning is needed here though rosoft compatibl in MIX C time of day Power C does time The graphics has al having to write it al bits like intercepting interrupts
73. who wishes to and develop them as an aid to their own learning and enjoyment and to the stock of public domain C source Shells two Unix style single tasking only though shells for MS DOS source code included so conversion to the ST amp beyond is a possibility why not give it C Language Tutorial 1 this text of the the example programs can be found on Volume 1 15 16 Editors version of editor one of the the Microl tation C Vu latest Emacs with sources and extensive document Now contains a macro language and several other enchancements in Cs the sources for XLISP object oriented version of the list processing language Languages 1 language compilers and interpreters This volume contains the Math a comprehensive collection functions set of MASM macros 8087 co processor for numerical of the usual Also contains a for the programs integration and matrix manipulation Unix Utilities 1 pattern matching language make project management tool stream editor complete with example sript convert Pascal to C and several minor utilities Unix Utilit processing ties 2 text and printing a couple of text format tters entabbers and detabbers menu driven setup programs for IBM and Epson printers
74. y overloading the operator again void operator intset i The compiler automatically selects the appropriate method of applying the operator The new type is declared as follows intset myset When a type is declared the following function is called to create the new typ in the current scope of the program intset intset int sz size sz set new int sz pos 0 The other function INTSET is a destructor It is automatically called when the program exits from the scope in which the type was created It s purpose is to destroy the allocated type intset intset delete set NEW and DELETE are similiar to the familiar C functions MALLOC and FREE The argument to NEW is a single type which is used to calculate the amount of space required DELETE returns the allocated space back to the operating system freestore Th quivalents in C are set malloc sizeof int sz free set Access to the elements of the set is achieved through the following function which is called whenever an element of an INTSET is accessed int amp intset operator int s if s lt 0 s gt size abort Set bounds out of range return set s Accessing an element is done in the same way as access to an array by using the subscription operator However
Download Pdf Manuals
Related Search
Related Contents
Micro Innovations PD1000MLS User's Manual marzocchi 50 Português Toshiba BDX1300KB User's Manual Samsung SCX-7328G User Manual(Basic Function) 平成25年12月期 決算短信〔日本基準〕(連結) JVC 1105RYMMDWJEIN User's Manual Installation Instructions & Maintenance Owner`s Maple 7/15 Rexel 2103762 folder Copyright © All rights reserved.
Failed to retrieve file