Home

GST Computer Systems Limited - Dilwyn Jones Sinclair QL Pages

image

Contents

1. QDOS_ LIB the extra QDOS library file containing all routines defined in section 5 of this manual STDIO H the standard I O header file s section 4 COMPIL Fa a C program to drive the compiler assembler and linker See section 2 4 WINDOW MGR a C program for adjusting programs default windows COMPILE C the source of the COMPILE program BACKUP a program to copy this tape In order to have enough space for your own programs you should copy the library files and the header file onto one microdrive which will then have room for your files Copy the others onto a different micro drive which will be used less frequently 1 4 What You Will Need to Use the Compiler and Write C Programs This compiler will run on any QL and does not need any add on RAM You will need a text editor program to create source files for example the ED program as provided with the Sinclair Assembler If you want to write large systems floppy disks will be useful because of the extra storage space but microdrives can be used for programs of up to a few hundred lines If you do not have a text editor you can use QUILL to create your program sources The files produced by QUILL cannot be read directly by the compiler you must first print the text into a print file using an appropriate printer driver Try pagelength 0 linelength 80 LF Line separator with no preamble or postamble 1 5 Making Back
2. 3 1 5 Unsigned Values The keyword unsigned can be put at the start of any declaration to indicate that the variables are to be treated as unsigned numbers Unsigned arithmetic is then used in expressions including unsigned variables Examples short i unsigned short u i 40000 overflow treated as 25536 u 40000 i S123 result is 12768 u u 2 result is 20000 char values range from 128 to 127 short values range from 32768 to 32767 int values range from 2147483648 to 2147483647 unsigned char values range from 0 to 255 unsigned short values range from 0 to 65535 unsigned int values range from 0 to 4294967295 3 2 Operators and Expressions 3 2 1 Constants The constants accepted by OC are decimal numbers eg 1 76890 1000000000 999 octal numbers eg 012 O377 starting with a zero digit hex numbers eg OxOa OXFF start with Ox es character constants eg Tat D string constants eg I am a string we Note that character constants actually generate int values and can have one or two characters in them whereas a string constant is actually an array of characters terminated by a null byte the value of a string constant is the address of the array String and character constants interpret the backslash character specially to specify some characters n is a newline code f ascii FORMFEED t ascii TAB b ascii BACKSPACE yA a single quote for use i
3. Local variables can be initialised with any expression but local arrays cannot be initialised Global int and char variables can initialised to constant values for example int i 0 j 345 678 123 char ees ngr Initialised and uninitialised variables can be mixed in Che same declaration Global arrays can be initialised by giving the initial values in curly brackets short int array 10 0 1 2 3 The number of initialised array elements can be less than the size of the array in which case the rest of the array is uninitialised The array size can be left out in which case the number of initialised elements is taken as the array size A character array or character pointer can be initialised with a string constant for example char pointer a string string another string In C strings are arrays of characters terminated by a zero byte 3 1 4 External Variables Global variables declared in other modules can be referenced using the extern directive This may not be used inside functions as it is treated like a global variable definition The symbol is then in scope until the end of the module If an array is declared external you do not specify the array size but use an empty pair of square brackets External variable directives cannot have initial values the variable can be initialised in the module which declares it example extern int qwerty pointer datarray
4. 5 3 Graphics Routines In these graphics routines all coordinates are in graphics units which are scaled to fit the window Angles are specified in hundredths of radians as QC does not support floating point Th llips eccentricity should also be passed as one hundred times the required number The graphics are drawn in the window selected by the selwindov routine 5 2 1 using the ink colour selected by ink 5 2 21 Note that graphics coordinates have the origin at the bottom left unlike pixel coordinates which have the origin at the top left 5 3 1 point x y int x y 5 3 2 line xl yl x2 y2 int xl yl x2 y2 5 3 3 arc xl yl x2 y2 angle int xl yl x2 y2 angle The arc is drawn between the two end points The sense of the arc depends on the sign of the angle if ve the curve is drawn in an anticlockwise direction 5 3 4 circle xpos ypos radius int xpos ypos radius This routine draws a circle which is a special case of the ellipse routine A circle is equivalent to an ellipse with eccentricity of 1 circle xpos ypos radius int xpos ypos radius ellipse xpos ypos radius 100 O0 5 3 5 ellipse xpos ypos radius eccentricity angle int xpos ypos radius eccentricity angle The radius specifies one of the ellipse radii The other radius is specified by radius times eccentricity Note that the eccentricity parameter is scaled by 100 so a value of 100 produces a circ
5. 7 3 Interpreting the Command Line Within a Program To use the command line passed from SuperBASIC the main function in the program should be declared as follows main argc argv int argc argv l argc is the number of arguments passed to the program plus one for the program name and argv is a pointer to an array of pointers to the argument strings If for example a program is started with the following command EX PROG lt MDV2_ DATAFILE ABC gt gt MDVI_ FILENAME def 99 Q arge will have the value 5 and argv will point to an array like this aly SS SSe gt ISS Ses Se gt nxa EE ege gt ABC fate ee eh gt def gt ae ee Se NGO kee Se Moe undefined Note that argv 0 points to a string containing an asterisk This is set up as a pointer to the program name on operating systems which support this The library routine getarg can be used to access parameters in this data structure It is defined as follows getarg n str size argc argv char str int n size argc argv The routine copies the nth parameter into the string str and it will be truncated to size bytes if it is too big arge and argv should be passed as received from the operating system eg main argc argv int argc argv char buff 20 I getarg 2 buff 20 argc argv getarg returns EOF and puts a null byte in str if it reaches the end of the argument TISE APPENDIX A Comp
6. lt constant expression gt For example int arrayl 10 100 char buff 512 J If an array is declared in an extern directive you leave out the array size as it is specified in the other module To access an element in an array the following syntax is used lt name gt lt expression gt The first element in the array is accessed with an offset of zero and if an array has N elements the last element is accessed using offset N 1 An array name on its own stands for the address of the first element of the array It can be used in expressions as the address of the array eg it can be assigned to a pointer but it cannot be altered itself Note that pointer syntax can also be used for addressing arrays the following two expressions are equivalent array offset array offset 3 5 3 Simulating Multidimensional Arrays Although QC will not create multidimensional arrays it is possible to set up an array of pOinters sometimes known as an Iliffe Vector which allows a single dimensional array to be accessed as though it is two dimensional An array of pointers is declared by putting both an asterisk and brackets on the array name for example int index 16J array of pOinters to integers table 256 array of integers If the elements of index are set to point to every 16th element of table we have simulated a 16 by 16 array The pointers could be set up as follows in
7. The null statement consists of just a semicolon It is often used in loops where the whole work of the loop is done by side effects of the control expression as in this example whil destt 4 sourcet D Here the bytes pointed to by source are copied to dest and both pointers are incremented The loop is terminated when a null byte is transferred as the result of the assignment is then zero 3 4 Functions and Program Structure 3 4 1 Program Structure A C program is built up from a number of functions There is no distinction in C between functions and procedures all functions return a value but the value can be undefined and the value returned by a function call can be ignored There is no main program in C but each program has one function called main which is called when the program is executed A C program sourc fal therefor contains a number of function declarations together with optional global or external variable declarations see 3 1 2 and or optional preprocessor directives see 3 6 3 4 2 Function Declarations lt name gt lt arg list gt lt arg declarations gt lt declarations gt lt statements gt A function declaration is constructed as above It starts with the function name function names are constructed in the same way as variable names followed by parentheses enclosing the list of arguments arg list is a list of zero or more argument names separate
8. a number of positional parameters the meaning of each parameter depends on its position within the list There are up to four positional parameters all filenames These are followed by the options An option is a word starting with a dash and may be followed by a filename parameter The positional parameters are first relocatable binary file name second linker control file name third listing file name fourth program file name The options are WITH lt filename gt This identifies the control file name if no relocatable binary file is named in the positional parameters NOPROG Do not produce a program file PROG lt filename gt Generate a program file NOLIST Do not produce a listing file LIST lt filename gt Send a listing to the named file NODEBUG Do not generate a debug file DEBUG lt filename gt Generate a debug file NOSYM Do not produce any symbol table or cross reference SYM Produce a symbol table CRF Produce a cross reference PAGELEN lt number gt Specifies number of lines per page in listing The filenames specified in the options are all optional but if specified they override the positional filenames If a filename is not specified in either place a default file name will be built from the source filename with extension MAP for listing files DEBUG for debug files and BIN for files program APPENDIX D DIFFERENCES BETWEEN QC AND STANDAR
9. binary files together If this is included in a link with an INPUT directive all the modules will be included in the link If a LIBRARY command is used the file will be searched and only those modules which resolve an undefined external reference will be extracted 2 6 The Window Manager Program This program is included to allow you to adjust the default window used by any program written in C or any of the utilities included on the tape EXEC W MDV2 WINDOW MGR The program will ask for the name of the program to adjust The window position and size can be adjusted interactively and the program asks for paper and ink colour The windows can be defined with tags the top line of the window is reserved to display the program name This program also allows you to adjust the stack space reserved by a program You should not change this for any of the supplied programs When you run a program with a tagged window it will be displayed during program initialisation If the windov is not tagged it is not cleared by the C program until it is written to This allows filter programs to be created uhich do not create a screen window 2 7 Using the Compiler with Floppy Disks If you have floppy disks on your QL you can easily transfer the programs across to take full advantage of the increased storage space and speed None of the programs will need modification to run on floppy instead of microdrive the compile prog
10. bytes COMPIL I Gl T COMPILE 210 C the source code in QC for the improved COMPILE program Use of the unlabelled Cartridge The cartridge should be alternated with QCl in MDV1l_ using QC2 in MDV2_ to hold the source file s that are alternately edited and then compiled If you have floppy disks you are strongly recommended to copy all the software onto disk in FLP1 which will also have sufficient room for your source files Remember to back up your cartridges prior to use
11. default then none of the statements in the block are executed See the break statement lt 3 3 8 for exiting a switch statement If the break statement is not used execution of the code will drop through past labels into the following statements Declarations are not allowed in the compound statement of a switch statement Example switch ch case a case e case i case 0O case u print Its a vowel break case y print Sort of a vowel break case f case h case l case r case s print Soft consonant break default if isalpha ch print Consonant else print Not a letter break 3 3 8 Break Continue and Return The statement break exits the current loop or switch statement The statement continue causes the rest of the current loop to be skipped and starts another iteration of the loop The statements return return lt expression gt exit the current function In the first case the result of the function is undefined In the second case the expression is evaluated and returned as the function result 3 3 9 Goto Statement The goto statement has the form goto lt label gt Where the label is defined in the current function like this lt label gt A label name is constructed in the same way as a variable name QC does not allow gotos into or out of blocks which have local variables 3 3 10 Null Statement
12. limit is 60 cases too many nested loops There are too many nested loops the compiler keeps track of them to handle continue and while statements The limit is 30 loops If you get this simplify the code or break it up into more functions wrong number of arguments The argument declarations in the function header do not match the arguments listed for the function APPENDIX B Summary of Library Routines This appendix contains a sorted list of the library functions function parameters is included for quick referenc A summary of Th section number where the function is specified is given on the right abort errcode int 4 10 13 abs n int n adate seconds int seconds arc xl yl x2 y2 angle int xl yl x2 y2 angle at line col int line col atoi str char str atoib str base char str int base avail abort int abort beep duration pitch int duration pitch block width height x y col int width height x y col border size colour int size colour calloc count size int count size ccargc 4 10 14 cfree pointer char 4 10 10 circle xpos ypos radius int xpos ypos radius clearerr fd int fd cls part int part csize width height int width height curdown curleft curright cursen switch int switch cursor xpos ypos int xpos ypos Curup date clock datevec int clock datevec delay ticks int ticks delete name char name dtoi str num char st
13. success or EOF on failure 4 3 13 feof fd int fd This routine returns YES if the fd has reached the end of file else NO 4 3 14 ferror fd int fd This routine returns the system status code associated with the last system call for fd ferror 0 is a special case it returns the system status code associated with the last file open call 4 3 15 clearerr fd int fd This clears any error status associated with the file fd 4 4 Random Access I O The following routines can be used to move around files A file position is a positive integer value giving the position in bytes from the start of file 4 4 1 rewind fd int fd This routine repositions a file to the beginning It returns NULL on success EOF on error It is equivalent to lseek fd 0 0 see below 4 4 2 getpos fd int fd This routine returns the current file position or EOF if the channel does not support random access 4 4 3 lseek fd offset from int fd offset from This routine positions the file to a position offset bytes from the place specified by from from 0 position relative to start of file from position relative to the current position from 2 position relative to the end of file The routine returns NULL on success or EOF on error 4 5 Formatted I O 4 5 1 printf str argl arg2 char str This function writes a formatted character string to the standard output channel str is a control st
14. the QL sound generator Duration is the period in units of 72 microseconds 14000 is therefore about one second Th lower th pitch number the higher th ton produced An even simpler way to drive the QL sound generator is provided in the main library writing a control G to the screen will generate a short beep Note that this routine and the one below return immediately To wait for the beep to finish call delay The time to delay is approx duration 256 tacks 5 4 7 warble duration pitch1 pitch2 interval step wrap fuzz rand int duration pitchl pitch2 interval step wrap fuzz rand This routine gives the user full control over the sound generator See the SuperBasic manual for more information on the various parameters 5 4 8 keyrow row int row This reads the QL keyboard directly It can be used to tell when two or more keys ar pressed S QDOS and SuperBasic documentation for more details Bits set in the result indicate which keys in that row are held down 5 4 9 random Returns a random integer 5 4 10 rnd min max int min max Returns a random integer in the specified range 5 4 11 readdir fd fname dirinfo int fd dirinfo char fname This routine is used to read the contents of a directory fd should be the result of a call to fopen with option d fname is a pointer to an array of characters big enough for a filename 37 characters is enough and dirinfo is a pointer to a
15. the simplest command line If the filename you give is MDV2 MYPROG the compiler will first look for MDV2 MYPROG_C and then for MDV2 MYPROG if the C file cannot be found The compiler will produce an output file named after the source program using th xample above it will create MDV2 MYPROG ASM You can put more filenames on the command line in which case all of them are read as input and the name of the first file is used to create the output filename You can also include a number of options on the commandline These all start with a dash followed by a letter upper or lower case M monitor write the first line of each function to the screen as it is compiled A alarm the compiler will bleep whenever it prints an error message to the screen P pause after printing an error message to the screen the compiler will wait for you to press the ENTER key before continuing C comments the C code is included in the output file as comments and the assembler code is formatted neatly D lt dir gt directory the specified directory is searched for include files Any device or directory name can be specified here eg D MDV2_ L lt name gt listing compiler listing output is sent to the named file or devic If a blank line is given to the compiler as a command line it will reprompt for another command line If no filenames ar given but the command line does contain
16. you add one to an integer pointer it points to the next integer although this is four bytes wide Any value added to or subtracted from an integer pointer is therefore scaled by the compiler to allow for the size of integers When the difference is taken between two pointers the result is the number of objects between them not the number of bytes If the pointers are not of the same type or do not point into the same array the results are undefined The syntax for declaring a pointer is the same as the syntax for declaring integer and char variables except that the variable name is prefixed with an asterisk lt type gt lt name gt If a pointer is used in an expression on its own the address is used or altered according to the expression If the pointer is preceded by an asterisk the value pomt ed to will be used in the expression or updated by the assignment for example int fred ptrl ptr2 ptr2 0 sets the pointer to zero ptrl amp fred sets the pointer to point at fred ptrl 0 sets the integer pointed to by ptrl fred fred ptrl uses the integer pointed to by ptril ptr2 ptrl copies the pointer value 3 5 2 Arrays Arrays in QC are restricted to a single dimension but see the next section They ar declared by following the array name with square brackets containing the array size which must be a constant expression lt type gt lt name gt
17. D C This appendix gives a brief summary of th differences between th OC language and the de facto C standard as defined in appendix A of The C Programming Language by Kernighan amp Ritchie Main Differences Floating point and structures and all language features relating to these types unions bitfields typedef are not implemented Th typ returned by a function in QC is always int and cannot be specified otherwis Multi dimensional arrays are not implemented in QC Other Differences Numbered according to K amp R 2 2 Identifiers External identifiers may not start with an underscore and all 8 characters are converted to uppercase The names of the 68000 registers are reserved 2 4 Constants The digits 8 and 9 are not accepted in octal constants The explicit long constant letter L at the end is not accepted 2 5 Strings Strings cannot be split using followed by newline 7 2 Unary operators Casts and the sizeof operator are not implemented 7 13 Conditional Operator This is not supported in QC 8 Declarations Extern and static declarations may not be used within blocks 8 6 Initialisation Global pointers cannot be initialised except char can be initialised with a string constant 9 7 Switch Statement Local variables are not allowed within a switch statement 9 11 Goto statement QC does not allow go to in functions with local variables in a blo
18. D2 The number of parameters passed to a routine D3 D4 D5 Not used D6 Always holds the value 1 D7 Always holds the value O AO The primary register holds the current value of the expression being evaluated Holds the result of a function when returned to caller Al The secondary register used when evaluating expressions and often holds the address of a variable being updated in an assignment A2 A3 Not used A4 Points to the middle of the program All functions are accessed via an offset from pointer A4 A5 Points to the base of the global variables All global variables are accessed using an offset from this register A6 The stack frame pointer points at the current function s local variables on the stack A7 The stack pointer points at the top of stack On the 68000 the stack grows down from high memory If you write assembly code to be interfaced with QC you are free to use any register but the following registers must be restored when you return to QC code D6 D7 A4 A5 A6 A7 6 2 The Memory Map of a QC Program High addresses are at the top of the diagram LINKER SECTION stack Zobne E A6 spare stack space TRAILER RELOC nn runtime library program ee RA S CCODE drea S GLOB globals Gasp a ee A5 S HEADER init code Sections S HEADER S TRAILER and S RELOC should not be used by the assembler
19. GST Computer Systems Limited QC USER MANUAL QC User Manual 9992 5 GST 63 1 01 NNNNMNNNNN PREP PP eee WWWWW WW Ov OV OY OV CD Om o Oo BEEP PEK vs vs VG VG Ab VG GA A k JJ On Us WNE J On UO BUNE OO Jon Us GA b i t HO OO JO OG GA r VG GA A k If CONTENTS INTRODUCTION Purpose and Scope of this Manual Conventions Used in this Manual QC Components list What You Will Need to Use the Compiler and Write C Programs Making Backup Copies Other Useful Manuals and Books Disclaimer Copyright and Trade Marks HOW TO RUN THE COMPILER Compiler Assembler Linker The Control Program COMPILE Linking More Complicated Programs The Window Manager Program Using the Compiler with Floppy Disks THE QC LANGUAGE Variables and Types Operators and Expressions Control flow and Statements Functions and Program Structure Pointers and Arrays Preprocessor Commands QC STANDARD I O RUNTIME LIBRARY Introduction Standard Input and Output File Input and Output Random Access I O Formatted I O Format Conversion Functions String and Character Handling Functions Character Classification Functions Character Conversion Functions Other System Facilities EXTRA QDOS LIBRARY ROUTINES Interfacing with QDOS Screen and Window Functions Graphics Functions Other QDOS Functions INTERFACING WITH ASSEMBLER CODE Register Usage The Memory Map of a QC Program QC Stack Structure Example of a Code
20. Insert THE COMMAND LINE AND 1 0 REDIRECTION Passlng a Command Line to a Program Redirecting I O Channels Interpreting the Command Line Within a Program APPENDIXES A Compiler Error Messages B Summary of Library Routines ie Summary of Compiler Assembler and Linker Options D Differences Between QC and Standard C 1 INTRODUCTION QC is a version of C specially produced for the Sinclair QL It is a subset of the standard C language as described in Kernighan amp Ritchie It contains all the features of RatC Appendix 1 of Berry amp Meekings plus the following extras switch for do goto statements logical operators amp amp unary operators comma expressions assignment operators short long integers unsigned values initialised local variables static variables amp functions All the language features are described in more detail in section 3 You ar recommended to read this manual thoroughly before using the compiler 1 1 Purpose and Scope of this Manual The QC User Manual provides an introduction to the QC compiler on the Sinclair QL It includes all the information you need to write programs using the compiler but does not attempt to teach the C language 1 2 Conventions Used in this Manual When QC keywords operators or variables are mentioned in the text they will be in bold UPPERCASE will be used for SuperBASIC commands and QDOS filenames When descri
21. JJ J JJ JJ k s k UW 0O OD PB UI Sos vs Un k JO GA OO s OO b i e CH CH H k k OO VO VO PA LA b i A ER 12 OWWN ol N A A N APPENDIX C SUMMARY OF COMPILER ASSEMBLER AND LINKER OPTIONS Summaries of assembler and linker options are included here for easy reference but they are not intended as a substitute for the relevant user manuals C 1 Compiler Options All filenames given to the compiler in the command line unless part of an option are input files which are read in the order specified Compiler options are single letters preceded by a dash Some of them take a parameter filenam M monitor write the first line of each function to the screen as it is compiled A alarm the compiler will bleep whenever it prints an error message to the screen P pause after printing an error message to the screen the compiler will wait for you to press the ENTER key before continuing C comments the C code is included in the output file as comments D lt dir gt directory the specified directory is searched for include files Any device or directory name can be specified here Note the parameter is mandatory in this command L lt name gt listing compiler listing output is sent to the named file or devic C 2 Assembler Options The assembler command line is in two parts First come a number of positional parameters the meaning of each paramete
22. S then the program is suspended until the next character is entered on the keyboard the character will not be read by the program 4 10 13 abort errcode int errcode exit errcode int errcode These routines are equivalent They close all open files and return to the system Errcode should be zero to indicate success or a QDOS error code 4 10 14 ccargc This function is called to determine the number of parameters passed to a user function See section 3 4 8 5 Extra QDOS Library Routines The routines defined in this section are included to allow access to the facilities of the QDOS operating system They are unique to QC and are non portable 5 1 Interfacing with QDOS trapl regpointer trap2 regpointer trap3 regpointer These three routines allow direct access to almost all of the QDOS facilities implemented as traps See the QDOS Software Developers Guide available from Sinclair Research Ltd for more information on how to use the traps Regpointer is a pointer to an array of 8 integers arranged as DO D1 D2 D3 A0 A1 A2 A3 all of which are updated with result of the trap To access the QDOS channel associated with a QC file fd defined as int fd use fd As an example here are some routines for unbuffered 1 0 INKEY This routine provides a similar facility to SuperBasic s INKEY function it reads the keyboard directly or returns 0 if no key was pressed during the timeout period W
23. a block within a function declares local variables another LINKinstruction is not generated the stack pointer A7 is just modified At the end of the function UNLK is used to restore the stack to its state before the LINK then RTS to return to the caller Parameters are removed from the stack by the caller All parameters are passed to functions as ints i e 32 bit longwords They are pushed onto the stack in the order they are declared so the first parameter is furthest from Ap and the last parameter is at address 8 A6 Amongst the local variables int and pointer variables occupy 4 bytes and are word aligned Short takes 2 bytes Character variables occupy just one byte gaps may be left between variables if you have a mixture of char and into If in doubt about how to access local variables in an assembly code insert in QC code look at the output from the compiler The simplest way to use assembly code inserts is to use the fact that the compiler leaves the result of an expression in the register AO which can then be used in your assembler code If assembly code appears at the end of a function the value you leave in AO will be the result of the function 6 4 Example of a Code Insert This example is taken from the graphics module in the library It uses the QDOS floating point routines to manipulate real numbers on a floating point stack fp_tos is a pointer into the array fp_stack char
24. ad readdir recol reverse rewind rnd scale scanf scroll sdate selwindow sign trcat EKchr tremp trcpy trip trlen trncat trncmp trncpy trrchr DD D Dm Im Io Dm Dm Io AN Oo tab toascii tolower toupper trapl trap2 trap3 under ungetc unlink utoi warble window write xtoi str char str fd buff count char buff int count fd fd fname dirinfo char fname int fd dirinfo table char table str char str fd int fd min max int min max scale xorg yorg str argl arg2 distance part int distance part value int value fd int fd n int n dest sour char dest sour E bat Eat ez trl str2 char strl str2 t sour char dest sour olour int colour tr char str st sour n char dest source int n Eri ebe Et char strl str2s gt pnt ny st sour n char dest sour int n Erer ehar eet E int scale xorg yorg L Char str WU n oO WU DD Oo Om OO o DA Jr nk Seo egpointer regpointer regpointer int regpointer int regpointer int regpointer switch int switch G d chax ez int E name char name str num char str int num duration pitchl pitch2 interval step wrap fuzz rand width height x y int width height x y fd buff count char buff int count fd str num char str int num Wu U U OAA MA oO E Es Es a vs ow AW WB ae Um EA JJ
25. alue pointed to amp address of this can only be applied to an lt lvalue gt and returns the address of the lvalue unary minus gives the 2 s complement of the expression logical not returns 0 FALSE If expression is non zero TRUE or 1 TRUE if the expression is zero FALSE 2 ones complement bitwise complement t gt increment and decrement these can be prefix or postfix operators The operand must be an lt lvalue If is used in prefix mode the value is incremented and the result of the expression is the new value If is used in postfix mode the value is incremented and the result of the expression is the original value works similarly 3 2 5 Binary Operators All binary operators group left to right so if an expression contains operators of equal precedence they are parsed from the left For example a b cis parsed as a b c The operators in this section are listed in order of decreasing precedence but operators of equal precedence are grouped together If either operand to an operator is unsigned then both operands are regarded as unsigned unsigned arithmetic is used and the result is unsigned multiply divide remainder Multiply overflow is ignored Division truncates towards zero the sign of the remainder is the same as the sign of the divisor It is always true that a b b a b a Provided b is non zero add subtract If an i
26. before the function is called It is this copy which is used by the function as its parameter Arguments are therefore passed by value If you want a function to be able to update some variable you pass the address of the variable to the function main int a b swap k amp b call function to swap variables note addresses are passed swap addra addrb this is the swap function int addra addrb the parameters are defined as pointers int temp temp addra addra addrb the locations pointed to addrb temp get modified here If a function has no parameters it is called by following the function name with an empty pair of parentheses eg func 3 4 4 Function Results All functions return results but the result returned by a function is undefined unless the function executed a return statement with a return value 3 3 8 In QC all functions return an int value Pointers can be returned from functions because a pointer variable is the same number of bits as an integer variable and the value is unchanged by QC when a pointer is assigned to an integer or vice versa 3 4 5 Static Functions If a function is declared to be static its name is not available to other modules just like a static variable The function name is just preceded by the word static in the declaration static lt name gt lt arg list gt lt arg declarations gt 3 4 6 External Functi
27. ber of arguments If you want a function with a variable number of parameters like printf it can find the number of parameters passed by calling the library routine ccargc This routine must be called at the start of the function before any other functions are called Using this and the information that the arguments are stored as ints in reverse order on the stack it is possible to access all the arguments correctly Note this is not portable Example func arg declare one arg for the function int arg as an integer int numargs this will hold the number of args argp this will be used as a pointer to them numargs ccargc get the number of args argp amp arg numargs l point at the first arg while numargs for each arg in order process argp process it amp step to next See section 6 for more information on the arrangement of function parameters on the stack 3 5 Pointers and Arrays 3 5 1 Pointers Variables which hold the addresses of other variables are called pointers They provide a very powerful and flexible mechanism for processing data Pointers are typed according to the type of object being pointed to This is because ints take four bytes of memory but chars take only one byte Pointers are manipULated according to the size of object pointed to if you add one to a character pointer it then points to the next character and if
28. bing the language in section 3 syntax examples will have keywords and other explicit language elements in bold but generic elements will be in angle brackets eg do lt statement gt while lt expression gt The library routines described in section 4 all have the start of the function declaration giving the function names its parameters and the types of all of the parameters This is all printed in bold The use of the word module in this manual refers to a group of subroutines compiled together in one go no Datter how many source files go into it It can refer to the assembler source file or the relocatable relocatable binary file or the C source file s 1 3 QC Components List The QC compiler comes with the following components two microdrive cartridges containing the compiler assembler linker runtime library files and example programs two blank microdrive cartridges for making backup copies a copy of A Book on C by R E Berry amp B A E Meekings an A5 ring binder containing this manual The microdrive tape labelled QC1 contains the following files QC the QC compiler QCASM the QC assembler used as pass 2 of the compiler LINK the QL Linker QC LINK the linker control file BACKUP a program to copy this tape The microdrive tape labelled QC2 contains the following files QC_LIB the standard library file containing all routines defined in section 4 of this manual
29. ch statement locals not allowed with goto Local variables are not allowed in a block if the function has any go to statements macro name table full There are too many macro names for the compiler s macro symbol table If you get this error you should break the program into several smaller modules There is room for around 100 macro names macro string queue full The space reserved for macro definitions has overflowed Break the program into smaller modules missing final closing bracket End of file was reached while still inside a function missing token Some syntax element eg a close bracket or a comma vas expected but not found The error message shows which character was expected multiple defaults Only one default label is allowed in a switch statement must assign to char pointer or array Only char pointers or char arrays can be initialised with string constants Simple char variables cannot be initialised in this way must be constant expression A variable expression was used where a constant expression is required eg when defining the size of an array or when initialising variables must declare locals at start of block Local variables must be declared before any statements within a block no apostrophe A string constant does not have a terminating apostrophe or single quote character no final End of file was reached within a compound statement n
30. cified in upper or lower case Included files cannot be nested if FILEA includes FILEB and FILEB includes FILEC then at the end of FILEC the rest of FILEB is skipped and the compiler continues reading FILEA This directive can only be used at the top level of a program ie amongst function declarations and global variable declarations It cannot be used within a function 3 6 2 Macro Substitution define lt macroname gt lt macrotext gt This directive defines a macro which then stands for the arbitrary text on the rest of th line When th macroname is encountered later in the module the compiler replaces it by the macro text Macro names must obey th sam rules as variable names but it is conventional to use uppercase for macro names Macro names are commonly used to give names to constants but they can be used to replace anything Macros can only be defined outside of functions but macro substitution occurs anywhere in the rest of the program Except in strings and character constants Note that macro substiution is performed on macro definition lines so macros can be defined in terms of earlier macros Macros with parameters are not implemented in QC 3 6 3 Conditional Compilation ifdef lt macroname gt ifndef lt macroname gt else endif These directives allow the compiler to compile different sequences of code according to whether the macro i
31. ck within the function 12 1 Token replacement Macros with parameters are not implemented in QC 12 3 Conditional Compilation The if directive is not implemented 12 4 Line control The line directive is not implemented ELECTRIC SOFTWARE Copyright C 1985 GST QC USER MANUAL ADDENDUM As a direct result of GST policy for constant development and improvement of its products QC is now supplied with the QED Screen Editor and an improved version of the COMPILE program The QC components list shown in section 1 3 of the QC User Manual is replaced by the following paragraphs QC Components List The QC Compilier is issued with the following components three microdrive cartridges containing the compiler assembler linker runtime library files a screen editor and example programs an Ab ring binder containing the QC and QED Screen Editor User Manuals QC1 and QC2 Cartridges The contents of microdrive cartridges labelled QCl and QC2 are unchanged These are described fully in section 1 3 of the QC User Manual Unlabelled Cartridge The contents of the microdrive cartridge unlabelled is as follows QED the QED Screen Editor for preparation and editing of QC or assembler programs Gm 210 an improved version of the COMPILE program that invokes the QED editor displays directory names and if a single floppy is used a free used sector count and file sizes in
32. d c Sd S c Sd c amp il amp i2 amp i3 could be used to read numbers terminated with non digits 123 456 789 as Sd reads up to a non digit and c skips one character 4 6 Format Conversion Functions 4 6 1 atoi str char str Convert Signed decimal number in str to an integer Leading whitespace is skipped A sign character or may optionally precede the first digit Conversion stops on the first non digit 4 6 2 atoib str base char str int base Convert unsigned number in specified base to an integer Leading whitespace is skipped Bases 2 to 16 are allowed Currently this routine destroys the contents of the string 4 6 3 itoa num str int num char str Convert the number to decimal left justified in the string If the number is negative a minus sign is generated The string is terminated by a null byte 32 bit integers can require up to ten digits or twelve bytes including sign amp null 4 6 4 itoab num str base int num char str int base Convert the unsigned number to a string using the specified base Bases 2 to 16 are allowed The string is terminated by a null Up to 33 bytes can be generated for base 2 4 6 5 dtoi str num char str int num Convert string from signed decimal put the result in num Returns the no of digits in the number or ERR if an error occurred eg overflow or no valid digits The routine does not accept leading spaces
33. d by commas These are the names by which the arguments are known within the function The names are in scope for the whole function arg declarations is a series of declarations specifying the types of the arguments Each argument must be declared as either int or char or a pointer to one of these two If the name is prefixed by an asterisk it names a pointer to the type specified eg afunction i j ch str int iy EI char ch str In this example i is declared to be an integer j is a pointer to an integer ch is a char and str is a pointer to char An array is passed to a function as the address of the first element in the array As an alternative to declaring an array argument type as a pointer using an asterisk it can be declared using a pair of square brackets eg func array int arrayl In this case the parameter array is still a pointer to the base of the array but the syntax suggests to the programmer that an array is to be processed After the argument declarations comes the function body which must be a compound statement A function which has no parameters is declared as follows func 3 4 3 Function Calls To call a function the function name is followed by a list of parameters in parentheses Each parameter can be any expression afunction value 123 amp intarray 17 O digit string Each parameter expression is evaluated and a copy of the value is made
34. een d open a directory see section 5 4 11 If this routine is called to open a channel to CON Tor SCR ie without any window specification then the same QDOS channel will be used as for stderr If you want a separate window put some window specification in the filename 4 3 2 freopen name mode fd char name mode int fd This can be used to close a channel then reopen it to another file It returns fd on success and zero on failure 4 3 3 fclose fd int fd This closes the channel and flushes any data still in memory to the operating system Zero is returned for success and a nonzero value for error 4 3 4 getc fd int fd fgetc fd int fd These routines are equivalent They return a character read from the specified input channel or EOF at end of file or if an error occurs 4 3 5 ungetc c fd char C int fd This function can be used to backup one place in an input file It does not actually reposition the file so it can be used on sequential devices The next time the file is read the valuewill be returned The value c is returned by ungetc unless previously saved character is in the buffer or if c has the value EOF in which case ERR is returned 4 3 6 fgets str size fd char str int size fd This routine is called to read a line from a file str is a pointer to a buffer and size is the maximum number of bytes which may be read Input is terminated by a newline charact
35. en the and the letter you can only put an asterisk which indicates skip this field and or a decimal number giving the field width A field is normally a sequence of printing characters terminated by a white space character A field is also terminated when the field width if specified has been reached If the conversion specification is SC a single character is read without skipping whitespace The format specifications are binary integer character Signed decimal number octal integer character string unsigned decimal number hexadecimal number Mo WO oe See the next page for examples of scanf 4 5 4 fscanf fd str argl arg2 int fd char str This routine works just like scanf but the first parameter indicates which channel to read from SCANF EXAMPL T Consider this statement scanf Ss Sc Sc Sx s Sd 3d Sa str amp cl amp c2 amp il amp 12 amp 13 If the input contains the following text abc defg 12 345678 9 Then the variables will receive these values str abc reads a string terminated by space GI M Ji reads the next char D Lg reads the next char the next string is skipped efg 5 12 reads a number terminated by a non digit 12 345 reads a 3 digit number i3 678 reads a number terminated by a non digit The next input call will read starting at the space after 345678 As a further example this statement num scanf
36. er A null byte is put in the buffer after the newline If the line is too big for the buffer size l data bytes are put in the buffer and null byte is put at the end The routine returns str on success or NULL on failure 4 3 7 putc c fd char c int fd fputc c fd char c int fd These routines are equivalent They write the character c to the file specified by fd The value c is returned unless an error occurs in which case EOF is returned 4 3 8 fputs str fd char str int fd This writes the string out to the file up to but not including the terminating null byte No newline is appended at the end 4 3 9 fflush fd int fd This routine is called to write data out to a file or device which has been buffered by the QC runtime library It can be used to force a partial line to be written out to the screen data to the screen is flushed automatically at the end of each line This routine is called by fclose 4 3 10 isatty fd int fd This routine returns YES if the channel has been opened to a serial device eg the screen or a comms line or NO if the device supports random access eg MDV or floppy disks 4 3 11 iscons fd int fd This routine returns YES if the channel is connected to the screen or keyboard otherwise it returns NO 4 3 12 delete name char name unlink name char name These routines are equivalent They delet th fii specified by the filename and return NULL on
37. fp stack 300 fp_tos FP Divide the next on stack by the top of stack if fp divide fp_tos get the floating point stack pointer into AO asm MOVE L A0 A1 get fp stack pointer in Al MOVE L A6 SP save C s A6 SUB L A6 A6 set A6 to zero for QDOS MOVEQ 10 DO0 QDOS code for divide MOVE L STLC AZ get address of FP routine JSR A2 call QDOS floating point MOVE L SP A6 restore C s A6 endasm fp tos 6 update our copy of stack pointer 7 The Command Line and I O Redirection If you have the QL Toolkit or if you start programs with the library routine exec it is possible to pass information to a program when you execute it You can also redirect the standard input and standard output channels 7 1 Passing a Command Line to a Program Using EX EW or ET you can pass a text string to a QC program started from SuperBASIC See the QL Toolkit documentation for full details The command looks like this EX lt programname gt lt string gt where lt string gt should be a SuperBASIC string expression The command line string will be parsed by the QC startup code so that the words in the command line can be processed individually It looks for sequences of non space characters separated by one or more spaces 7 2 Redirecting I O Channels If data filenames are included in the EX command line the first datafile will be taken as the program s standard i
38. ger array pointer O gets window width pointer 1l gets height pointer 2 gets cursor x position from left pointer 3 gets cursor y position from top 5 2 3 border size colour int size colour This routine is used to update the window border Size is the required border width and colour is the required colour 5 2 4 window width height x y int width height x Y Change window definition width and height specify the new window size x and y specify the window position The cursor is reset to the top left corner of the window position 0 0 5 2 5 cursen switch int switch This routine turns the cursor on or off according to the value of switch 0 means off non zero means on 5 2 6 at line col int line col This routine positions the cursor at the specified line and character position within the window 5 2 7 tab col int col This routine positions the cursor at the specified column number 5 2 8 nextline This routine moves the Cursor to the start of the next line 5 2 9 curleft This routine moves the cursor left one spac 5 2 10 curright This routine moves the cursor right one space 5 2 11 curup This moves the cursor to the next row up 5 2 12 curdown This moves the cursor to the next row down 5 2 13 cursor xpos ypos int xpos ypos This moves the cursor to the specified pixel addressed position 5 2 14 scroll distance part int distance part The windo
39. gt lt statement gt This is functionally equivalent to lt expressionl gt while lt expression2 gt lt statement gt lt expression3 gt The first expression is the loop initialisation the second is the loop termination test evaluated before each iteration the third expression is the loop re initialisation often incrementing some counter Anyone of the thr xpressions may be left out if expression2 is left out the loop is executed continuously see the break statement in 3 3 8 For example for count O count int CF c getchar if c EOF break putchar c Variables used in a for statement must be predeclared unlike some other languages 3 3 7 Switch Statement The switch statement has the form switch lt expression gt lt compound statement gt The expression is evaluated and the result is used to select which part of the compound statement is executed Each statement in the compound statement can be labelled with one or more case prefixes case lt constant expression gt There can also be one default prefix of the form default The value of the switch expression is compared with each case constant If one of the case constants matches control is passed to the statement after that prefix If no case constant matches and there is a default prefix control is passed to the statement after the default prefix If no constant matches and there is no
40. his error try breaking the program down into smaller and simpler modules illegal address The address operator amp was used on something which does not have an address illegal argument name There is some syntax error in the function argument name eg it is a reserved word illegal array size Negative array sizes are illegal illegal function or declaration This is a syntax error at the level of defining functions or global variables the compiler cannot make sense of the declaration illegal symbol The symbol name contains invalid characters or is a reserved word invalid expression An expression term is invalid Valid terms are constants variables or string constants Label names and reserved words are invalid line too long After the preprocessor has performed macro substitutions the line has exceeded 128 characters You should simplify the line or break it over several lines literal queue overflow There are too many string constants in a function or they are too long The compiler saves the string constants until the end of the function There is room for about 800 characters If you get this error break the function into smaller functions local symbol table overflow lhere are too many local symbols in the function for the compiler s local symbol table Break the function into smaller functions locals not allowed in switch Local variables are not allowed in the block controlled by a swit
41. ht 4 7 7 strncpy dest sour n char dest sour int n The string is copied like strcpy but if it is too short it is padded to n chars with spaces and if it is too long it is truncated to n characters A null byte is then put at the end Overlapping strings should be avoided 4 7 8 strlen str char str This function returns the length of the string excluding the null terminator byte 4 7 9 strchr str c char str c This searches for the first occurrence of the character c in the string and returns a pointer to it It returns NULL if the character is not found 4 7 10 strrchr str c char str c This searches for the last occurrence of the character c in the string and returns a pointer to it It returns NULL if the character is not found 4 7 11 reverse str char str This routine reverses the order of the characters in the string 4 7 12 lexcmp strl str2 char strl str2 This routine compares strings like strcmp except it uses lexorder to compare characters rather than using ASCII sequence 4 7 13 lexorder cl c2 char cl c2 This routine compares two characters using dictionary order rather than ASCII order Control codes come first Other non alpha chars precede all alphabetic chars Uppercas letters sort immediately befor th corresponding lowercase letters DEL copyright comes last Top bit set characters are undefined 4 8 Character Classificatio
42. i inkey timeout int timeout int regs 8 regs O 1 IO FBYTE regs 3 timeout regs 4 stderr AO channel to CON_ trap3 regs if regs O if no error return regs 1 return key code else return 0 OUTSCR xx This is a companion routine to INKEY It is used to write characters to the screen avoiding zx OC s buffers xf outser Cer A int ch int regs 8 regs 0 5 IO SBYTE regs 1l ch D1 char to write regs 3 l regs 4 stderr AO channel to CON_ trap3 regs return regs 0 return status code if any 5 2 Screen and Window functions All the functions in this section call TRAP 3 to update the screen They return QDOS status codes In order to change text colour or style within a line you must call fflush to write out the text before the screen driver call 5 2 1 selwindow fd int fd This routine is used to select which window to is to be used for graphics and screen driver routines The default is the window connected to stderr 5 2 2 getwindow flag pointer int flag pointer This routine is used to enquire the window size and cursor position Flag is 0 to get the result in pixel coordinates or nonzero to get the result in character coordinates Pointer specifies where the results are to be put it should be an array of four integers or a pointer into a big
43. iler Error Messages When the compiler detects errors in the code it prints an error message on the screen and to the listing file if a listing is being produced Error messages to the screen consist of the line in which the error was detected followed by a line with a pointer indicating where in the line the error was detected followed by a message If option A was selected the compiler will bleep to draw your attention If option P was selected the compiler will pause and wait for you to type ENTER before proceeding At the end of the compilation the compiler will print a list of any undefined symbols on the screen and to the listing file The list is in two parts first any undeclared names which have been used as function names are listed these are assumed to be external functions This is followed by a list of undeclared names which have not been used as function names These are assumed to be undefined globals and are treated as an error The compiler error messages are listed below in alphabetical order together with explanations already defined The symbol has already been used You can create a local variable with the same name as a global variable or a local in another block but you cannot have two global variables with the same name or two local variables in the same block with the same name bad label The label name is invalid or missing can t subscript Yo
44. ine left adjusts the string Starting at the first non blank character th bytes are moved to the start of the string up to and including the terminating null byte 4 7 2 strcat dest sour char dest sour The string sour is appended to the string dest which must be big enough it is up to the programmer to ensure this 4 7 3 strncat dest sour n char dest source int n This is like streat except that n limits the number of characters which can be taken from sour It does not fill the buffer with spaces like strncpy 4 7 4 strcmp strl str2 char strl1 str2 This returns an integer value less than equal to or greater than zero depending on whether the string strl is less than equal to or greater than str2 Comparison is based on the ASCII values of the characters in the strings but the result is undefined for strings containing bytes in the range 128 to 255 Le with the top bit set it will give the right answer for string equality but the inequality result is undefined If the strings match up to the length of the shortest one that string is considered to be the lesser of the two 4 7 5 strncemp strl str2 n char strl str2 int n This function is like stremp but a maximum of n characters are compared 4 7 6 strcpy dest sour char dest sour The string sour is copied to dest Beware of overlapping strings a string can be shuffled to the left using this routine but not to the rig
45. iple assignments so for example fred bert 1 thing 0 sets thing to zero then sets a location in array bert to zero then sets the object pointed to by fred to zero lt lvalue gt lt expression gt This is simple assignment the expression is evaluated and the result saved in the variable or location specified by the lvalue When assigning to a char the value is truncated to 8 bits and higher bits are lost Values are truncated to 16 bits for assignment to short objects Other assignment operators perform some arithmetic on an object lt lvalue gt lt op gt lt expression gt lt op gt can be anyone of JS gt gt lt lt amp Note there can be no space between the lt op gt and the equals symbol The behaviour of a lt op gt D is equivalent to a a lt op gt b but a is only evaluated once 3 2 7 Comma Expressions lt expression gt lt expression gt A pair of expressions separated by a comma are evaluated left toright The value of the first expression is discarded and the expression on the right gives the value of the whol xpression Comma expressions are typically used wher th syntax requires an expression but a number of side effects are required for example in the control expression of a while loop while ptrl fred increment c ptrl c EOF print c Note that when the context imposes another mearing on the comma character eg in the list
46. le 5 3 6 scale scalefactor xorg yorg int scalefactor xorg yorg The scale is adjusted so that the height of the window is equivalent to scalefactor graphics units xorg and yorg give the internal graphics coordinates of the bottom left hand corner of the window The default scale is 100 and the default origin is 0 0 5 3 7 gcursor xorg yorg right down int xorg yorg right down The cursor position is taken from xorg and yorg in graphics coordinates plus an offset right and down in pixel coordinates 5 3 8 111 switch int switch Area fill is turned on or off according to the value of switch 5 4 Other QDOS Facilities 5 4 1 delay ticks int ticks Delay for a short period A tick is one fiftieth of a second 5 4 2 adate seconds int seconds Adjust the clock forwards or backwards by a number of seconds Returns the clock value in seconds from the first of January 1961 5 4 3 qdosdate Returns the clock value 5 4 4 date clock datevec int clock int datevec Converts clock to a formatted date datevec should be a pointer to an array of 7 integers arranged as datevec 0 year datevec 1 month datevec 2 day in month datevec 3 weekday 0 Sunday 1 Monday 6 Saturday datevec 4 hour datevec 5 minute datevec 6 second 5 4 5 sdate value int value Set the clock 5 4 6 beep duration pitch int duration pitch This routine provides a simple interface to
47. n Functions These routines return YES or NO according to whether the char belongs to the specified class of characters They do not currently recognise any of the Sinclair extended character set for foreign alphabets 4 8 1 isalnum c char c alphanumeric characters 0 9 A Z a z 4 8 2 isalpha c char c alphabetic characters A Z a z 4 8 3 isascii c char c ASCII characters 0 127 4 8 4 iscntrl c char c ASCII control codes 0 31 4 8 5 isdigit c char c digits 0 9 4 8 6 isgraph c char c graphic characters 33 127 excludes space 4 8 7 islower c char c lowercase letters a z 4 8 8 isprint c char c printing characters 32 127 includes space 4 8 9 ispunct c char c punctuation characters ASCII chars excluding control codes and alphanumerics 4 8 10 isspace c char c whitespace characters space and control codes 4 8 11 isupper c char c uppercase letters A Z 4 8 12 isxdigit c char c hex digits 0 9 A F a f 4 9 Character Conversion Functions 4 9 1 toascii c char C Converts c to ASCII it leaves it unchanged 4 9 2 tolower c char c If c is an uppercase letter return the lowercas quivalent lse return Cc 4 9 3 toupper c char c If c is a lowercase letter return the uppercas quivalent else return c 4 10 Other System Facilities These are assorted system facilities which are often provided in a similar form in o
48. n array of eight integers The routine returns zero normally or EOF at the end of the directory Pn example of the use of this routine main int dirinfo 8 char filename 40 int fd fd fopen mdv1l_ d while readdir fd filename dirinfo 0 printf The information in the directory entry is put into the array as follows dirinfo 0 file size dirinfo 1l key dirinfo 2 file type dirinfo 3 type dependent information dirinfo 4 7 dirinfo 5 date of last update dirinfo 6 date of last access dirinfo 7 date of last backup Read the QDOS documentation for more information on the information held in a directory Note that not all of these information fields are implemented on all device drivers 5 4 12 exec progname optstr flag char progname optstri int flag This routine allows you to run another program progname is the name of the program to run and optstr is passed to the program as a parameter string If flag is zero the routine returns immediately after the subprogram was started If nonzero the routine waits for the subprogram to finish A QDOS status code is returned by this routine If the routine waits for the subprogram to finish the status code returned by that program is returned by this routine 6 Interfacing with Assembler Code 6 1 Register Usage The 68000 registers are used by QC as follows DO D1 Hold temporary values for arithmetic calculations
49. n character constants SI a double quote for use in strings the backslash character itself 123 up to 3 digits interpreted in OCTAL 0 special case of above null x12 up to 2 digits interpreted in HEX 3 2 2 Expressions Some operators require an lvalue operand An lvalue is an expression referring to an object a variable name is the simplest case but array indexing and pointer indirection are also lvalues When signed char or short values are used in expressions they are sign extended to int When unsigned char or short values are used in expressions they are padded with zeroes to unsigned long A summary of operator precedence is given at the end of this section 36238 s Overflow is always ignored when evaluating an expression 3 2 3 Primary Expressions Constants variables and strings are all primary expressions Any expression in parentheses is a primary expression Parentheses are used in this way to control expression evaluation order A primary expression followed by an expression in square brackets is a primary expression This is used to index arrays A primary expression followed by a sequence of zero or more expressions enclosed in parentheses is a function call all of which is a primary expression 3 2 4 Unary Operators Unary operators group right to left The unary operators are indirection the expression is normally a pointer and the result of the expression is the v
50. ndard output channel The value c is returned if the write completed sucessfully or EOF is returned if an error occurred 4 2 3 puts str char str This writes the string to the standard output up to but excluding the null byte at the end It then writes a newline to the standard output 4 3 File Input and Output These routines allow access to any file or device In these calls the parameter fd is a file descriptor which can be the value returned by one of the open calls it should have the type pointer to int or one of standard file descriptors stdin for standard input stdout for standard output stderr for standard error output Data written to stderr is always sent to the screen it cannot be redirected like stdout It is also permissible to read from stderr in which case the keyboard will be read regardless of stdin These standard files can be used without calling fopen 4 3 1 fopen name mode char name mode This opens a channel to the named file It returns a file descriptor on success or the value 0 if it fails mode can be one of the following strings TEN open for read the file must already exist w open for write in which case the file is deleted first if it already exists and then re created a open for append the file is created if it does not already exist and is positioned to the end of file if it does exist This cannot be used for output to devices such as the scr
51. nput and the last one will be used as the standard output but if pipes have been set up these will be used instead Examples EX QC MYFILE C MYFILE ASM This runs the compiler which reads from MYFILE C on the default data device and writes to MYFILE ASM on the program device Note that filenames here can have the device name omitted as it is appended by the toolkit but the extensions must be defined explicitly Gl EX MYPROG_ BIN DATAFTILI This runs the program which reads from file DATAFILE but standard output still goes to the screen EX MYPROG BIN DATAFILE AFILE TO ANOTHERPROG In this case program MYPROG reads from DATAFILE ignores and sends its output down a pipe to ANOTHERPROG which can be another QC program See the QL Toolkit documentation For compatibility with other operating systems the UNIX like convention using angle brackets can also be used for I O redirection If the following forms appear in the EX option string they wi Ll override any other I O redirection No spaces are allowed between the angle bracket characters and the filenames her lt filenam open the file as standard input gt filenam open the file as standard output gt gt filenam open the file as standard output but append the text to the end of the file Redirection specifications like these are not passed to the user program as parameters s below
52. nteger value is added to or subtracted from a pointer it will be scaled by the base type of the pointer so if p is a pointer into an array ptl is a pointer to the next object in the array If two pointers to objects of the same type are subtracted the result is scaled to give the number of objects between the two pointers This is only useful if both pointers point into the same array lt lt shift left gt gt shift right Shift left fills with zero bits Shift right unsigned fills with zero bits but preserves the sign bit on signed values lt less than lt less than or equal gt greater than or equal gt greater than equal not equal These operators return 1 TRUE if the relation is true and 0 FALSE if the relation is false Unsigned comparisons are made if either operand is unsigned amp bitwise and bitwise exclusive or bitwise inclusive or These operators perform a bitwise operation on the values and return an integer result amp amp logical and Logical or The logical operators test whether values are zero or nonzero and return a value which is zero or one They guarantee left to right evaluation of operands but the right operand is not evaluated if the left operand determines the result 3 2 6 Assignment Operators Assignment operators group right to left and the result of the operation is the value assigned It is therefore possible to perform mult
53. o matching if A preprocessor directive else or endif does not have a matching ifdef or ifndef directive no quote A string constant is not terminated properly String constants may not be split onto multiple lines no semicolon A semicolon is missing from the end of a statement This message commonly appears at the start of the following statement not a label The name after the gato is already defined as something other than a label not allowed with block locals A goto statement is not allowed in a function which has local variables in a block below the level of the main function block not an argument A name is defined in the declarations in a function header which is not one of the arguments of the function not in switch A default or case label may not appear outside of a switch statement only allowed in a loop A continue statement can only be used within a loop A break statement can be used in a loop or a switch statement output error An error occurred vhen writing out to the output file or listing file This normally means that the microdrive tape or floppy disk is full This is a fatal error staging buffer overflow The output buffer used for peephole optimisation has overflowed This only happens on complicated statements and expressions If you get this simplify your code too many cases There are too many cases in the switch statement for the compiler s switch table The
54. oduce a program MDV2 MYPROG BIN which can then b xecuted using EXEC or EXEC W See appendiz C for a list of linker options Note that the linker control file assumes that the library file QC _LIB is on the tape in MDV2 You will have to edit the control file to change this arrangement If there are any errors or warnings from the linker or any multiply defined or undefined symbols do not try to run the program 2 4 The Control Program COMPILE A program called COMPILE is included on the tape to drive the compiler assembler and linker together It will ask for the name of the file to be compiled and will construct command lines for each program You should leave out the C and just enter the name of the program EXEC W MDV2_COMPILI GI Press Fl to select the compile option Name of file to compile MDV2_MYPROG Note that the compile program can also be used to execute other programs including the Window Manager and Backup programs The source of this program is included with the compiler as an example program and to allow you to change it if you wish If you do recompile this program you must then adjust its data requirement down to 2k in order to leave enough memory for the compiler You can do this using the window manager program see 2 6 2 5 Linking More Complicated Programs To link more complicated programs involving more than one module you should create your own link cont
55. of parameters to a function a comma expression should be enclosed in brackets to avoid confusing the compiler for example func Ca LP D3 ke GL 3 2 8 Operator Precedence Summary starting with most binding lt expression gt s lt expression gt lt primary gt lt primary gt lt expression gt amp lt lvalue gt lt expression gt lt expression gt lt expression gt lt lvalue gt lt lvalue gt lt lvalue gt lt lvalue gt amp amp lt expression gt lt expression gt lt expression gt lt expression gt function call array indexing indirection address of unary minus unary logical not unary bitwise complement pre increment pre decrement post increment post decrement multiplicative operators additive operators arithmetic shifts inequalities equality operators bitwise logical operators logical and logical or t gt gt lt lt amp lt expression gt lt expression gt 3 3 Control flow and Statements assignment operators comma operator A note on semicolons in C semicolons are not used to separate or terminate all statements they are part of the syntax of certain statements 3 3 1 Expression Statement lt expression gt An expression statement is an expression followed by a semicolon Usually expression statements are assignments or function calls a 1 ptrt t func a b c 3 3 2 C
56. ompound Statement Block lt declarations gt lt statements gt A compound statement allows several statement Examples used wher th local variables to statements to b It also allows language syntax requires on be defined A compound statement is a pair of braces curly brackets containing zero or more declarations followed by zero or more statements For example int a b a getval b getval putval a b 3 3 3 Conditional Statement The two forms of the conditional statement are if lt expression gt lt statement1l gt if lt expression gt lt statementl gt else lt statement2 gt In both cases the expression is evaluated If it is true nonzero statementl is executed In the second case if the expression is false zero statement2 is executed As there is no endif construction in C an else is always associated with the most recent incomplete if statement 3 3 4 While Statement while lt expression gt lt statement gt The expression is evaluated and if true non zero the statement is executed and the loop repeated until the expression becomes false 3 3 5 Do Statement do lt statement gt while lt expression gt The statement is xecuted then th xpression is evaluated If the expression is true nonzero the loop is repeated 3 3 6 For Statement The for statement has the form for lt expressionl gt lt expression2 gt lt expression3
57. ons If a function exists in another module it can be declared as external as follows extern int lt name gt extern int lt name gt Note that the function list is not declared here The word int can be left out of the declaration as the default type in an extern declaration is int The second form of the declaration is treated as equivalent to the first by OC but full C compilers treat it as declaring a pointer to a function At the end of a module any undefined symbols are assumed to be external functions 3 4 7 Parameters which are Function Addresses It is possible to call a function and pass as one of the parameters the address of another function which it in turn calls This can be done in QC using the following syntax in the declaration and in the call lt name gt For example funcl is a function which takes a function parameter and is declared like this funcl arg int arg arg is a pointer to a function arg UI the function is called like this The call to funcl with parameter func2 looks like this the function is named on its own with no parentheses funcl func2 3 4 8 Functions with a Variable Number of Parameters Normally the number of parameters passed to a function when it is called should be the same as the number of parameters declared for the function Some functions eg printf in the library 4 5 1 require a variable num
58. or a plus sign but will accept an optional leading minus sign 4 6 6 otoi str num char str int num Convert string from unsigned octal put the result in num Returns no of digits in the number or ERR on overflow It does not skip leading spaces 4 6 7 utoi str num char str int num Convert string from unsigned decimal put the result in num Returns no of digits or ERR on overflow It does not skip leading spaces 4 6 8 xtoi str num char str int num Convert string from unsigned hex put the result in num Returns no of digits or ERR on overflow Upper and lowercas letters are accepted It does not skip leading spaces 4 6 9 itod num str size int num size char str Convert integer num to signed decimal right justified in str If size gt 0 size 1 bytes are put in str followed by a null byte If size 0 it searches for a null byte in str If size lt 0 size bytes are put in str with no null terminator Returns str 4 6 10 itoo num str size int num size char str Convert integer num to octal otherwise like itod 4 6 11 itou num str size int num size char str Convert integer num to unsigned decimal otherwise like itod 4 6 12 itox num str size int num size char str Convert integer num to hex otherwise like itod Digits A to F are written in uppercase 4 7 String and Character Handling Functions 4 7 1 left str char str This rout
59. pointer name mode fd char name mode int fd d fd str argl arg2 int fd char str 4 5 4 buff size count fd char buff int size count fd 4 10 4 xorg yorg right down int xorg yorg right down Bes n str size argc argv char str yint n Size argc argv fd int fd 4 3 4 4 2 1 fa ant fd 4 4 2 flag pointer int flag pointer DeLee colour int colour DL c char c 4 8 1 c char c 4 8 2 c char c 4 8 3 fd int fd 4 3 10 ey eat es 4 8 4 fd int fd 4 311 c char c 4 8 5 c char c 4 8 6 G t ehate 4 8 7 c char c 4 8 8 c char c 4 8 9 c char c 4 8 10 c char c 4 8 11 c char c 4 8 12 num str int num char str 4 6 3 num str base int num char str int base 4 6 4 num str size int num size char str 4 6 9 num str size int num size char str 4 6 10 num str size int num size char str 4 6 11 num str size int num size char str AS63142 row int row 5 4 8 str char str 4 7 1 strl str2 char strl str2 Aod kh cl c2 char cl1 2 47 13 xl yl x2 y2 int xl yl x2 y2 Ba fd offset from int fd offset from 4 4 3 count int count 4 10 8 5 2 8 str num char str int num 4 6 6 switch int switch 5 2 24 distance part int distance part a EE colour int colour D2 619 x y int x y 5 3 1 pause int pause str argl arg2 char str 4 5 1 c fd char c int fd ABT GINEO WEE puts qdosdate random re
60. programmer all code should be put into section S CCODE along with code generated by the compiler The location pointed to by A4 is referenced by the symbol MS so functions can be referenced as follows JSR func MS A4 Using this mechanism any function within 32k of A4 can be accessed in a position independent manner allowing QC programs of up to around 64k in size MS is actually defined to be 32k from the base of the program Global variables can be declared in assembler code by switching to section S GLOB and using DC L or DC B to declare variables and their initial values The location pointed to by A5 is referenced by the symbol G so other global variables can be referenced as follows MOV MOV Za globname G A5 DO B D1 globchar G A5 Gl GI 6 3 QCStack Structure QC uses the 68000 instructions LINK and UNLK to maintain a stack frame structure on entry to a function the function parameters have been pushed onto the stack by the caller The function uses a LINK instruction to reserve space for local variables declared at th outer level of the function The stack then looks like this high addresses at the top of the diagram function parameters RETURN ADDRESS LINK WORD space for local variables The function parameters are accessed using positive offsets from A6 and the local variables are accessed using negative offsets If
61. r int num ellipse x y radius ecc angle int x y radius ecc angle exec progname optstr flag char progname optstr int flag exit errcode Int 4 10 13 fclose fd int fd feof Ed int fid ferror fd int fd fflush fa int fd fgetc Ed int fd fgets str size fd char str int size fd fill switch int switch flash switch int switch fopen name mode char name mode fount fountl fount2 char fountl fount2 fprintf fd str argl arg2 int fd char str fputc ce fd char cy int SE errcode Wu Bis S Sos e oO oO ous OD Om OO OO OD A o A vs oOo H Oo On b GO Gs k MN A Sift MNNNNNNDN W W Ww 4 NEOA GA bie O Wid ad WN oO On 7 LI pointer 4 eld 16 25 12 9 LO 25 A3 ll 12 errcode E d Us Ui Us WA wok vs ee E e WANUN WWW GA GA GA Ww J k k A OO Ons OFF W A W N l fputs fread free 4 10 10 freopen fscanf fwrite gcursor getarg 4 10 11 getc getchar getpos getwindow ink isalnum isalpha isascii isatty iscntrl iscons isdigit isgraph islower isprint ispunct isspace isupper isxdigit itoa itoab itod itoo itou itox keyrow left lexcmp lexorder line lseek malloc nextline otoi over pan paper point poll 4 10 12 printf putc putchar str fd char str int fd 4 3 8 buff size count fd char buff int size count fd 4 10 3 pointer char
62. r depends on its position within the list There are one to three positional parameters all filenames These are followed by the options An option is a word starting with a dash and may be followed by a filename parameter The positional parameters are first source filename second optional listing filename third optional binary filename The options are NOLIST Do not produce a listing file ERRORS lt filename gt Only send error messages and erroneous lines to the named file This option sets the NOSYM option LIST lt filename gt Send a listing to the named file NOBIN Do not produce any relocatable binary output BIN lt filename gt Send relocatable binary output to the named file NOSYM Do not produce any symbol table or cross reference SYM Produce a symbol table and cross reference NOLINK Produce absolute binary instead of relocatable binary The filenames specified in the options are all optional but if specified they override the positional filenames If a filename is not specified in either place a default file name will be built from the source filename with extension LIST for listing files and REL for relocatable binary files By default the QC assembler does not produce a listing file If a listing file is selected a symbol table will be included by default C 3 Linker Options The linker command line is in two parts like the assembler command line First come
63. ram actually checks to see if FLP1_ exists and if not it defaults to MDV1 You will need to change the linker control file which names the library files This is an ordinary text file which can be updated with a text editor 3 The QC Language This section defines the language facilities provided by the QC compiler It is not intended to teach the C language you are recommended to read the book included with the compiler or one of the other books listed in the introduction if you want to learn how to program in C C comments start with and end with and they cannot be nested 3 1 Variables and Types Variables are the fundamental data objects manipulated in a program All variables in QC must be declared before they are used 3 1 1 Variable Names Variabl names ar mad up from letters digits and the underline character and they must start with a letter Only the first eight characters in a variable name are significant Uppercase and lowercase are treated as different by the compiler it is conventional in C to use lowercase for variable names and uppercase for symbolic constants see 3 6 2 Some names are reserved including all of the keywords eg if else int and names beginning with c_ are reserved for use within the runtime library The names of the 68000 registers eg AO DO USP are also reserved 3 1 2 Declarations Variables can be declared globally outside of any function in which case the
64. rder is O black l blue 2 red 3 magenta 4 green 5 cyan 6 yellow 7 white 5 2 19 paper colour int colour Set paper colour The paper colour is used when clearing the screen and is also used to fill the space left behind by scroll and pan 5 2 20 strip colour int colour Set strip colour The strip colour is used as the background colour when text is written to the screen Unless it is being written as transparent text The strip colour is often set to the same as the paper colour 5 2 21 ink colour int colour Set ink colour This is used for text and graphics except when writing in XOR mode 5 2 22 flash switch int switch Set or unset flash mode Nonzero switch turns on flashing zero switch turns it off Flashing only works if the machine is in 8 colour mode 5 2 23 under switch int switch Set underlining on or off according to the value of switch 5 2 24 over switch int switch Set writing and plotting mode switch 1 XOR mode switch 0 character background switch 1 transparent mode 5 2 25 csize width height int width height Character size and spacing width 0 6 pixels spacing 1 6 pixels on 8 pixels spacing 2 12 pixels wide 3 12 pixels on 16 pixels spacing height 0 for single height 1 for double height 5 2 26 block width height xpos ypos colour int width height xpos ypos colour Fill a rectangle specified in pixel coordinates in the specified colour
65. ring which contains ordinary characters and conversion specifications The ordinary characters are written out unchanged Each conversion specification indicates how the corresponding arg is to be converted before output The function returns as its result the number of characters written The conversion specifications start with the character and end with a letter Between thes characters can be optional fields giving extra formatting information a minus sign indicates left justify within field a decimal number gives field width if specified with a leading zero the field will be padded with zeros a decimal fraction number of characters to take from string The terminating letter indicates the type of conversion b unsigned integer convert to binary c character d signed integer convert to signed decimal o unsigned integer convert to octal s string address u unsigned integer convert to unsigned decimal x unsigned integer convert to hexadecimal If an invalid character is encountered it is written out as a text o character so in the format string is written out as S See the next page for some examples of printf 4 5 2 fprintf fd str argl arg2 int fd char str This routine is just like printf except that the first parameter indicates the channel to be written to PRINTF EXAMPLE Vertical bars have been included in the format string examples
66. rol file If you want to specify all the modules named in the control file take the supplied control file MDV1 QC LINK and replace the line INPUT with an input directive for each of the C modules to be linked together Then run the linker with a command line like this WITH MDV2 MYCONTROL FIL Gl Alternatively if you still want to name one of the modules in the link command line leave in the INPUT line which tells the linker when to read the module named in the command line Follow this line by an INPUT directive for all the other modules The linker control file should look like this SECTION S HEADER SECTION S GBASE SECTION S GLOB SECTION S CCODE SECTION S RBASE SECTION S RELOC SECTION S TRAILER INPUT MDV2_ MYPROG11 REL INPUT MDV2 MYSUBS_ REL INPUT MDV2_OTHERCODE REL LIBRARY MDV2 QDOS LIB LIBRARY MDV2_ QC LIB DEFINE GS C GLOBBA DEFINE MS C ENDGLO 8000 DATA 8K If you have a complicated program which uses lots of stack you may want to change the DATA directive in the control file to change the workspace used by the program If you do not use any of the routines listed in section 5 of this manual you can delet th lin which calls for library file QDOSLIB to speed up the link operation Other parts of the control file should not be changed You can create a subroutine library by appending a number of relocatable
67. s defined or not defined Different versions of the same program can then be compiled by changing define directives at the top of the program Conditional compilation directives can occur anywhere in a program 3 6 4 Assembler Code fasm endasm These directives allow assembler code to be included in a program They can be used outside of functions or within a function anywhere where a statement is allowed All 68000 instructions are accepted For details of assembler syntax see the Sinclair Macro Assembler manual See section 6 for information on accessing C data from assembler code 3 6 5 Listing Control Directives nolist list page These directives can be used to control the layout and contents of the compiler listing You might like to turn off listing for an included file containing a lot of macro definitions or maybe start a new listing page for each function in a program 4 QC Standard I O Runtime Library 4 1 Introduction The description of each function in this section starts with the function declaration in bold which defines the order and types of the parameters Programs which use the run time library should include the standard header file STDIO H which defines symbols for file descriptors and values returned by the library routines For example include MDV2 STDIO H include lt FLP1 STDIO H gt If compiler option D is used see section 2 it is possible to leave out
68. some options it will take data typed in at the keyboard as the compiler source and send its output to the screen If there are any compilation errors the compiler will return a not complete error code to QDOS 2 2 Assembler The output from the compiler is in assembler source format An assembler is included with the compiler Run the assembler by typing EXEC W MDV1_QCASM When the assembler asks for a command line type the name of your file the final ASMcan be omitted eg MDV2_MYPROG This will then generate a binary file named after the source file in this case MDV2 MYPROG REL To produce a listing at the assembler stage include in the command line the option LIST lt filename gt S appendix C for a list of the assembler options If any errors are reported by the assembler it will return a not complete status to QDOS Check for functions or variables with the same name as 68000 registers You can ignore any warnings from the assembler 2 3 Linker The linker is then used to combine your program with the runtime library A linker control file is included on QCl called QC LINK Run the linker by typing EXEC W MDV1 LINK and when the linker asks for a command line type the name of the binary file the final _REL can be omitted followed by the name of the control file and any other linker options eg MDV2_MYPROG MDV1 OC LINK NOLIST This will pr
69. stored data profit or contracts which may arise from any error defect or failure of the QC compiler software GST Computer Systems Limited has a policy of constant development and improvement of their products We reserve the right to change manuals and software at any time and without notice 1 8 Copyright and Trade Marks The QC compiler software on microdrive cartridge together with the QC User Manual are Copyright C 1984 GST Computer Systems Limited QC is a trademark of GST Computer Systems Limited QLkit and QLToolkit are trademarks of QJump Limited QL QDOS and Microdrive are trademarks of Sinclair Research Limited UNIX is a trademark of Bell Laboratories 2 HOW TO RUN THE COMPILER The QC compiler takes C program sources created with a text editor and converts them to assembler language text This must then be assembled using the QC assembler the Sinclair Macro Assembler can also be used This produces a relocatable binary file One or more relocatable binary files are then combined with the runtime library by the linker to create an executable program file 2 1 Compiler The compiler program is called QC Put the tape marked QCl or a copy of it in MDVl and your data tape which is created from a copy of QC2 in MDV2 then type the command EXEC W mdv1 QC The compiler will start up and ask for a commandline You can now type the filename of the C program you want to compile this is
70. the device or directory name from filenames used in include statements eg include lt stdio h gt The definitions in STDIO H include EOF 1 returned by read routines when they reach the end of file ERR 2 which is returned by some routines when an error is detected NULL 0 used as a null pointer value It is returned by some routines as a success code and by others as an error code YES 1 NO 0 These values are returned by some routines eg feof 4 2 Standard Input and Output The following library routines can be called by programs which use only the standard input and standard output channels a character at a time By default the keyboard is read as the standard input and standard output is sent to the screen See section 7 for information on I O redirection Note that input and output are buffered by the QC library if you call putchar to write a character to the screen it will not appear immediately Buffers are flushed at the end of each line but see routine fflush 4 3 9 The screen window used for standard I O will not be cleared by the library until it is written to This means that programs Which have redirected channels may not have any visible screen window Tagged windows are always displayed see section 2 6 4 2 1 getchar Returns a character read from the standard input channel or the value EOF at the end of file 4 2 2 putchar c int e Writes the character to the sta
71. ther C implementations System facilities which are specific to QDOS are listed in section 5 4 10 1 abs n int n This returns the absolute value of the integer n 4 10 2 sign n int n This returns 1 0 or 1 according to the sign of n 4 10 3 fread buff size count fd char buff int size count fd This reads from file fd into buff count items size bytes long It performs a binary transfer It returns the actual number of items read use feof or ferror to determine if at end of file or if an error occurred 4 10 4 fwrite buff size count fd char buff int size count fd This writes count items size bytes long from buff to file fd It performs a binary transfer It returns the actual number of items written use feof or ferror to determine if at end of file or if an error occurred 4 10 5 read fd buff count char buff int count fd This reads count bytes from file fd into buff It performs a binary transfer It returns the actual number of bytes read use feof or ferror to determine if at end of file or if an error occurred 4 10 6 write fd buff count char buff int count fd This writes count bytes from buff to file fd It performs a binary transfer It returns the actual number of bytes written use feof or ferror to determine if at end of file or if an error occurred 4 10 7 calloc count size int count size This allocates count size bytes of memory and ini
72. tialises them to zero It returns a pointer to the memory or zero if memory is exhausted 4 10 8 malloc count int count This allocates count bytes of uninitialised memory It returns a pointer to the memory or zero if out of memory 4 10 9 avail abort int abort This routine returns the amount of fr space left between the program and the stack If abort is nonzero and the stack has overwritten the program the program will be aborted 4 10 10 free pointer char pointer cfree pointer char pointer These routines are equivalent They return memory to the heap which was grabbed by calls to calloc or malloc Any record may be released back to the heap at any time it is not necessary to release records in the reverse order of allocation The pointer must be a pointer as returned from calloc or malloc otherwise the system heap may be corrupted a pointer into a record allocated from the heap will not work 4 10 11 getarg n str size argc argv char str int n size argc argv Extract the nth argument from the program s parameter string and copy it into str maximum size size See section 7 for more info on program parameter strings 4 10 12 poll pause int pause This routine looks to see if there are any keystrokes pending for the program If pause is zero any character is returned to the caller or zero if there are no chars waiting If pause is non zero and the character is control
73. to ay for Esc ege Fag index i amp table 16 i The array can then be accessed as follows index a b index a takes one of the pointers in index and gives a pointer into array table The second array access gives us one of the elements in that part of array table 3 6 Preprocessor Commands These preprocessor commands effectively manipulate the C source before it is compiled The preprocessor can be considered as an extra pass to the compiler but the changes are actually made as the compiler reads the text All of these preprocessor directives should be used on a line on their owm 3 6 1 The Include Directive The include directive has two forms the angle brackets are part of the syntax here include filename include lt filename gt No spaces are allowed within the quotes or brackets This directive allows a file to be included in the compilation at this point It can be used to make exactly the same set of definitions and directives in each of a set of modules Both forms of the directive as shown above are accepted by the compiler but they are treated the same The two different forms indicate to some C compilers to search for the file in different directories The filename specified in this directive should be the complete QDOS name of the file to be included or if compiler option D is being used Section 2 the device or directory prefix can be omitted The filename can be spe
74. to show the effect of spacing and field width in output using printf They are not mandatory if name is the string fred and score is an integer 67 then printf Ss s score is d S name score will print fred s score is 67 format string parameter s printout od 1234 1234 66d 1234 1234 6 6d 1234 1234 606d 1234 001234 od e 1 sul I 4294967295 SX 1 ffffffff Sb 1234 10011010010 6060 1234 002322 S04x 1234 04d2 SC At A ED Kai Al KEES A 41 Ss computer computer S5s computer computer 12s computer computer 12s computer computer 12 4s computer comp 9s 02da S02d 02d Thursday 14 2 85 Thursday 14 02 85 4 5 3 scanf str argl arg2 char str This routine performs an inverse function to printf it reads text from the standard input and interprets it according to the conversion specifications in str The control string str may contain only conversion specifications and white space which is ignored All the args passed to scanf should be addresses of variables where th results are placed Or for strings a buffer pOinter The function returns as its value the number of fields processed it will stop early if input data does not match the conversion specification If no fields have been read and it reaches end of file it will return EOF Conversion specifications are similar to printf but betwe
75. u cannot subscript something which is not a pointer or an array cannot assign to pointer Pointers cannot be initialised except character pointers which can be initialised with a string constant cannot assign An attempt was made to assign to something which is not an lt lvalue gt This error message is also produced if the increment or decrement operators are used on something which is not an lt lvalue gt An lt lvalue gt is something which can validly appear on the left side of an assignment typically a variable or a subscripted array or an indirected pointer cannot initialise local arrays Global arrays can be initialised but local arrays cannot error opening file An error occurred opening one of the files named in the command line This is a fatal error expression too complicated The compiler can handle most expressions with up to 12 levels of brackets If you get this error simplify the expression or break it into several smaller expressions and use some temporary variables failed to open include file An error occurred when attempting to open an include file The compiler will carry on after this error function body must be a compound statement QC requires a function body to be a compound statement other statement types are not allowed global symbol table overflow There are too many global symbols for the compiler s symbol tables There is room for around 200 global symbols If you get t
76. up Copies It is strongly recommended that you make backup copies of the supplied tapes before using them The program BACKUP is supplied on each tape and can be used to copy the tape We suggest you then use the new tapes for running the compiler and save the originals as backups To run the BACKUP program put the tape to be copied in MDVl and a blank tape in MDV2 then enter the command EXEC W MDV1 BACKUP The program will ask for the source and destination directory names if you just press ENTER it will assume source is MDVl and destination MDV2 It will ask whether you want to format the blank tape If you do not format the tape it will ask whether you want to over write files on the backup tape if they already exist This option is useful when you make backups of your working tapes It will then copy the tape 1 6 Other Useful Manuals and Books The C programming Language B W Kernighan and D M Ritchie Prentice Hall A C Reference Manual S P Harbison and G L Steel Prentice Hall The C Programming Tutor L A Wortman and T O Sidebottom Prentice Hall Note that some of the example programs in these books will not work with QC because they use features of C not supported by the compiler 1 7 Disclaimer Under no circumstances will GST Computer Systems Limited be liable for any direct indirect incidental or consequential damage or loss including hut not limited to loss of use
77. w or part of it is scrolled vertically by the specified amount A positive distance moves the text down on the screen Part is interpreted as follows part 0 Scroll window part 1 Scroll top of window lines above cursor line part 2 Scroll bottom of window lines below cursor line 5 2 15 pan distance part int distance part The window or part of it is scrolled horizontally by the specified amount A positive distance scrolls the text to the right Part is interpreted as follows part 0 Pan whole window part 3 Pan whole cursor line part 4 Pan cursor line from cursor to end of line 5 2 16 cls part int part The window or part of it is cleared to the current paper colour Part is interpreted as follows part 0 Clear window part 1 Clear top of window above cursor line part 2 Clear bottom of window below cursor line part 3 Clear whole cursor line part 4 Clear cursor line from cursor to end of line 5 2 17 fount fountl1 fount2 char fountl fount2 This routine is used to select the character fount for the window A zero fount address selects the default fount See QDOS documentation for details of the fount data structure If a character to be written is not defined in fountl then fount2 will be checked 5 2 18 recol table char table This routine recolours a window Table is an array of eight bytes chars giving the new colour 0 7 for each of the colours currently displayed on the screen O
78. y are in scope from the declaration to the end of the module or locally in which case the variable is private to the block or routine The types supported by QC are int 32 bits wide long 32 bits wide same as int short 16 bits wide char 8 bits wide pointers 32 bits wide A declaration specifies an optional storage class specifier followed by an optional type specifier followed by a list of variable names Global variables can have the following storage classes none the variable is available outside the module in extern directives extern the variable must be declared without a storage class specifier in some other module See 3 1 4 static the variable is private to the module The storage class specifier is ignored on local variables The allowed classes are auto and register It is not normally specified The names ar accepted for compatibility with other compilers Storage classes static and extern are not accepted by QC for local variables The types short and long can be used on their own or they can be followed by int An asterisk before the name creates a pointer to objects of that type whereas square brackets are used to define arrays and enclose the array size Examples int lower upper step long value short int word char c buffer 512 str Note that when defining an array of N locations they are accessed using offsets 0 to N 1 3 1 3 Initialising Variables

Download Pdf Manuals

image

Related Search

Related Contents

Téléchargement  Mode d`emploi - Le Jardin de Catherine  ASUS D550MA LV8619 User's Manual  Téléchargez la brochure en cliquant ici  User and Installation Manual  CRONÓMETROS DT480EL  FG-274  Avaya Reporting for Contact Center User's Manual  TK-250 - K9ROD  USER`S MANUAL - Public Surplus  

Copyright © All rights reserved.
Failed to retrieve file