From 4ef03db48333ce0dce4496bc9183df126326ad1e Mon Sep 17 00:00:00 2001 From: michael Date: Sun, 27 Jun 1999 15:23:28 +0000 Subject: [PATCH] + Corrections of error pointed out by Luk Vandelaer --- docs/prog.tex | 340 ++++++++++++++++++++++++++++++-------------------- docs/user.tex | 4 +- 2 files changed, 208 insertions(+), 136 deletions(-) diff --git a/docs/prog.tex b/docs/prog.tex index 9ed17543dd..279f98f616 100644 --- a/docs/prog.tex +++ b/docs/prog.tex @@ -89,7 +89,7 @@ Since the compiler is continuously under development, this document may get out of date. Wherever possible, the information in this manual will be updated. If you find something which isn't correct, or you think something is missing, feel free to contact me\footnote{at -\var{michael@tfdec1.fys.kuleuven.ac.be}}. +\var{Michael.VanCanneyt@wisa.be}}. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Compiler switches @@ -119,10 +119,12 @@ counterparts. % Local switches \section{Local directives} \label{se:LocalSwitch} -Local directives have no command-line counterpart. They influence the -compiler's behaviour from the moment they're encountered until the moment -another switch annihilates their behaviour, or the end of the unit or -program is reached. +Local directives can occur more than once in a unit or program, +If they have a command-line counterpart, the command-line artgument is +restored as the default for each compiled file. The local directives +influence the compiler's behaviour from the moment they're encountered +until the moment another switch annihilates their behaviour, or the end +of the current unit or program is reached. \subsection{\var{\$A} or \var{\$ALIGN}: Align Data} @@ -162,8 +164,28 @@ If False and Bofu then \subsection{\var{\$C} or \var{\$ASSERTIONS} : Assertion support} -This switch is recognised for Delphi compatibility only. Assertions are not -yet supported by the compiler, but will be implemented in the future. +The \var{\{\$ASSERTION\}} switch determines if assert statements are +compiled into the binary or not. If the switch is on, the statement +\begin{verbatim} +Assert(BooleanExpression,AssertMessage); +\end{verbatim} +Will be compiled in the binary. If te \var{BooleanExpression} evaluates to +\var{False}, the RTL will check if the \var{AssertErrorProc} is set. If it +is set, it will be called with as parameters the \var{AssertMessage} +message, the name of the file, the LineNumber and the address. If it is not +set, a runtime error 227 is generated. + +The \var{AssertErrorProc} is defined as +\begin{verbatim} +Type + TAssertErrorProc=procedure(const msg,fname:string;lineno,erroraddr:longint); +Var + AssertErrorProc = TAssertErrorProc; +\end{verbatim} +This can be used mainly for debugging purposes. The \file{SYSTEM} unit sets the +\var{AssertErrorProc} to a handler that displays a message on \var{stderr} +and simply exits. The \file{SYSUTILS} unit catches the run-time error 227 +and raises an \var{EAssertionFailed} exception. \subsection{\var{\$DEFINE} : Define a symbol} @@ -172,7 +194,7 @@ The directive {$DEFINE name} \end{verbatim} defines the symbol \var{name}. This symbol remains defined until the end of -the current module, or until a \var{\$UNDEF name} directive is encountered. +the current module (i.e. unit or program), or until a \var{\$UNDEF name} directive is encountered. If \var{name} is already defined, this has no effect. \var{Name} is case insensitive. @@ -180,7 +202,7 @@ insensitive. \subsection{\var{\$ELSE} : Switch conditional compilation} -The \var{\{\$ELSE \}} switches between compiling and ignoting the source +The \var{\{\$ELSE \}} switches between compiling and ignoring the source text delimited by the preceding \var{\{\$IFxxx\}} and following \var{\{\$ENDIF\}}. Any text after the \var{ELSE} keyword but before the brace is ignored: @@ -354,7 +376,7 @@ compilation continues as if the directive wasn't there. \subsection{\var{\$IFOPT} : Start conditional compilation} The \var{\{\$IFOPT switch\}} will compile the text that follows it if the -switch \var{switch} is currently in the specified state. +switch \var{switch} is currently in the specified state. If it isn't in the specified state, then compilation continues after the corresponding \var{\{\$ENDIF\}} directive. @@ -366,6 +388,8 @@ As an example: \end{verbatim} Will compile the writeln statement if generation of type information is on. +{\em Remark:} The \var{\{\$IFOPT\}} directive accepts only short options, +i.e. \var{\{\$IFOPT TYPEINFO\}} will not be accepted. \subsection{\var{\$INFO} : Generate info message} If the generation of info is turned on, through the \var{-vi} command-line @@ -441,12 +465,12 @@ i.e. an identifier, keyword or operator. The compiler will look for the file to include in the following places: \begin{enumerate} -\item It will look in the path specified in the incude file name. +\item It will look in the path specified in the include file name. \item It will look in the directory where the current source file is. \item it will look in all directories specified in the include file search path. \end{enumerate} -You can add files to the include file search path with the \var{-I} +You can add directories to the include file search path with the \var{-I} command-line option. \subsection{\var{\$I} or \var{\$INCLUDE} : Include compiler info} @@ -458,8 +482,8 @@ In this form: where \var{xxx} is one of \var{TIME}, \var{DATE}, \var{FPCVERSION} or \var{FPCTARGET}, will generate a macro with the value of these things. If \var{xxx} is none of the above, then it is assumed to be the value of -an environment variable. It's value will be fetched, and inserted in the coe -as if it were a srtring. +an environment variable. It's value will be fetched, and inserted in the code +as if it were a string. For example, the following program \begin{verbatim} @@ -467,8 +491,8 @@ Program InfoDemo; Const User = {$I %USER%}; -joe begin - Write ('This program was comilped at ',{$I %TIME%}); +begin + Write ('This program was compiled at ',{$I %TIME%}); Writeln (' on ',{$I %DATE%}); Writeln ('By ',User); Writeln ('Compiler version : ',{$I %FPCVERSION%}); @@ -477,7 +501,7 @@ end. \end{verbatim} Creates the following output : \begin{verbatim} -This program was comilped at 17:40:18 on 1998/09/09 +This program was compiled at 17:40:18 on 1998/09/09 By michael Compiler version : 0.99.7 Target CPU : i386 @@ -493,14 +517,14 @@ The \var{\{\$L filename\}} or \var{\{\$LINK filename\}} directive tells the compiler that the file \file{filename} should be linked to your program. -the compiler will look for this file in the following way: +The compiler will look for this file in the following way: \begin{enumerate} \item It will look in the path specified in the object file name. \item It will look in the directory where the current source file is. \item it will look in all directories specified in the object file search path. \end{enumerate} -You can add files to the object file search path with the \var{-Fo} +You can add directories to the object file search path with the \var{-Fo} option. On \linux systems, the name is case sensitive, and must be typed @@ -536,7 +560,7 @@ function strlen (P : pchar) : longint;cdecl;external; end. \end{verbatim} -If one would issue the command the command +If one would issue the command \begin{verbatim} ppc386 foo.pp \end{verbatim} @@ -675,7 +699,7 @@ use when storing enumerated types. It is of the following form: {$MINENUMSIZE xxx} \end{verbatim} Where the form with \var{\$MINENUMSIZE} is for Delphi compatibility. -var{xxx} can be one of \var{1,2} or \var{4}, or \var{NORMAL} or +\var{xxx} can be one of \var{1,2} or \var{4}, or \var{NORMAL} or \var{DEFAULT}, corresponding to the default value of 4. @@ -683,7 +707,7 @@ As an alternative form one can use \var{\{\$Z1\}}, \var{\{\$Z2\}} \var{\{\$Z4\}}. Contrary to Delphi, the default size is 4 bytes (\var{\{\$Z4\}}). -So the follwoing code +So the following code \begin{verbatim} {$PACKENUM 1} Type @@ -721,7 +745,7 @@ two that is equal to or larger than the element's size. The default alignment (which can be selected with \var{DEFAULT}) is 2, contrary to Turbo Pascal, where it is 1. -More information on this and an exmple program can be found in the reference +More information on this and an example program can be found in the reference guide, in the section about record types. {\em Remark:} @@ -747,7 +771,7 @@ The generation of overflow checking code can also be controlled using the \var{-Co} command line compiler option (see \userref). \subsection{\var{\$R} or \var{\$RANGECHECKS} : Range checking} -By default, the computer doesn't generate code to check the ranges of array +By default, the compiler doesn't generate code to check the ranges of array indices, enumeration types, subrange types, etc. Specifying the \var{\{\$R+\}} switch tells the computer to generate code to check these indices. If, at run-time, an index or enumeration type is specified that is @@ -776,7 +800,7 @@ object file, and all object files are put together in a big archive. When using such a unit, only the pieces of code that you really need or call, will be linked in your program, thus reducing the size of your executable substantially. Beware that using smartlinked units slows down the -compilation process, because a separate object file must be creayed for each +compilation process, because a separate object file must be created for each procedure. If you have units with many functions and procedures, this can be a time consuming process, even more so if you use an external assembler (the assembler is called to assemble each procedure or function code block). @@ -849,7 +873,7 @@ will display the follwing message: \begin{verbatim} Press to continue \end{verbatim} -before waiting for a keypress. Careful ! this may interfere with automatic +before waiting for a keypress. Careful ! This may interfere with automatic compilation processes. It should be used for debuggig purposes only. \subsection{\var{\$WARNING} : Generate warning message} @@ -900,7 +924,7 @@ The command-line compiler switch \var{-Sa1} has the same effect as the \section{Global directives} \label{se:GlobalSwitch} Global directives affect the whole of the compilation process. That is why -they also have a command - line counterpart. The command-line counterpart is +they also have a command-line counterpart. The command-line counterpart is given for each of the directives. \subsection{\var{\$APPTYPE} : Specify type of application (Win32 only)} @@ -912,13 +936,16 @@ application. By default, a program compiled by \fpc is a console application. Running it will display a console window. Specifying the \var{\{\$APPTYPE GUI\}} directive will mark the application as a graphical application; no console window will be opened when the application is run. +If run from the command-line, the command prompt will be returned immediatly +after the application was started. Care should be taken when compiling \var{GUI} applications; the \var{Input} and \var{Output} files are not available in a GUI application, and attempting to read from or write to them will result in a run-time error. It is possible to determine the application type of a windows application -at runtime. The \var{IsConsole} constant, declared as +at runtime. The \var{IsConsole} constant, declared in the Win32 system unit +as \begin{verbatim} Const IsConsole : Boolean @@ -953,7 +980,7 @@ The compiler itself doesn't do the emulation of the coprocessor. To use coprocessor emulation under \dos go32v1 there is nothing special required, as it is handled automatically. (As of version 0.99.10, the -go32v1 platform will no longer be supported) +go32v1 platform is no longer be supported) To use coprocessor emulation under \dos go32v2 you must use the emu387 unit, which contains correct initialization code for the @@ -974,7 +1001,7 @@ long as the only type used is single or real. \subsection{\var{\$G} : Generate 80286 code} -This option is recognised for Turbo Pascal compatibility, but is ignored, +This option is recognised for Turbo Pascal compatibility, but is ignored. \subsection{\var{\$INCLUDEPATH} : Specify include path.} @@ -1007,12 +1034,12 @@ practice to use makefiles and makefile variables. This switch (not to be confused with the \var{\{\$L file\}} file linking directive) is recognised for Turbo Pascal compatibility, but is ignored. -generation of symbol information is controlled by the \var{\$D} switch. +Generation of symbol information is controlled by the \var{\$D} switch. \subsection{\var{\$LIBRARYPATH} : Specify library path.} This option serves to specify the library path, where the linker looks for -static or dynamic libraries. \var{\{\$LIBRARYPATH XXX} will add \var{XXX} +static or dynamic libraries. \var{\{\$LIBRARYPATH XXX\}} will add \var{XXX} to the library path. \var{XXX} can contain one or more paths, separated by semi-colons or colons. @@ -1041,7 +1068,7 @@ follows: \begin{verbatim} {$M StackSize,HeapSize} \end{verbatim} -Wher \var{StackSize} and \var{HeapSize} should be two integer values, +where \var{StackSize} and \var{HeapSize} should be two integer values, greater than 1024. The first number sets the size of the stack, and the second the size of the heap. (Stack setting is ignored under \linux). The two numbers can be set on the command line using the \var{-Ch} @@ -1050,8 +1077,8 @@ and \var{-Cs} switches. \subsection{\var{\$MODE} : Set compiler compatibility mode} The \var{\{\$MODE\}} sets the compatibility mode of the compiler. This -is equivalent to setting one of the command-line options \var{-So} or -\var{-Sd} or \var{-S2}. it has the following arguments: +is equivalent to setting one of the command-line options \var{-So}, +\var{-Sd}, \var{-Sp} or \var{-S2}. it has the following arguments: \begin{description} \item[Default] Default mode. This reverts back to the mode that was set on the command-line. @@ -1059,7 +1086,8 @@ the command-line. enabled. This is the same as the command-line option \var{-Sd}. \item[TP] Turbo pascal compatibility mode. Object pascal extensions are disabled, except ansistrings, which remain valid. This is the same as the command-line option \var{-So} -\item[FPC] FPC mode. +\item[FPC] FPC mode. This is the default, if no command-line switch is +supplied. \item[OBJFPC] Object pascal mode. This is the same as the \var{-S2} command-line option. \item[GPC] GNU pascal mode. This is the same as the \var{-Sp} command-line @@ -1067,7 +1095,7 @@ option. \end{description} For an exact description of each of these modes, see appendix \ref{ch:AppD}, -on page \pageref{ch:AppD} +on page \pageref{ch:AppD}. \subsection{\var{\$N} : Numeric processing } @@ -1173,7 +1201,7 @@ generation is not yet fully supported. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Using conditionals and macros %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\chapter{Using conditionals, Messages and macros} +\chapter{Using conditionals, messages and macros} \label{ch:CondMessageMacro} The \fpc compiler supports conditionals as in normal Turbo Pascal. It does, however, more than that. It allows you to make macros which can be used in @@ -1253,7 +1281,7 @@ with the patch-number of the compiler. 'OS' needs to be changed by the type of operating system. Currently this can be one of \var{DOS}, \var{GO32V2}, \var{LINUX}, \var{OS2}, \var{WIN32}, \var{MACOS}, \var{AMIGA} or \var{ATARI}. -This symbol is undefined if you specify a target that is different from the +The \var{OS} symbol is undefined if you specify a target that is different from the platform you're compiling on. The \var{-TSomeOS} option on the command line will define the \var{SomeOS} symbol, and will undefine the existing platform symbol\footnote{In versions prior to @@ -1295,8 +1323,8 @@ The prototype of this construct is as follows : In this directive \var{expr} is a Pascal expression which is evaluated using strings, unless both parts of a comparision can be evaluated as numbers, in which case they are evaluated using numbers\footnote{Otherwise -\var{\{\$If 8>54} would evaluate to \var{True}}. -If the complemete expression evaluates to \var{'0'}, then it is considered +\var{\{\$If 8>54\}} would evaluate to \var{True}}. +If the complete expression evaluates to \var{'0'}, then it is considered false and rejected. Otherwise it is considered true and accepted. This may have unexpected consequences : \begin{verbatim} @@ -1332,30 +1360,30 @@ begin {$if (fpc_version=0) and (fpc_release>6) and (fpc_patch>4)} {$info At least this is version 0.9.5} {$else} -{$fatalerror Problem with version check} +{$fatal Problem with version check} {$endif} {$define x:=1234} {$if x=1234} {$info x=1234} {$else} -{$fatalerror x should be 1234} +{$fatal x should be 1234} {$endif} {$if 12asdf and 12asdf} {$info $if 12asdf and 12asdf is ok} {$else} -{$fatalerror $if 12asdf and 12asdf rejected} +{$fatal $if 12asdf and 12asdf rejected} {$endif} {$if 0 or 1} {$info $if 0 or 1 is ok} {$else} -{$fatalerror $if 0 or 1 rejected} +{$fatal $if 0 or 1 rejected} {$endif} {$if 0} -{$fatalerror $if 0 accepted} +{$fatal $if 0 accepted} {$else} {$info $if 0 is ok} {$endif} @@ -1363,51 +1391,51 @@ begin {$if 12=12} {$info $if 12=12 is ok} {$else} -{$fatalerror $if 12=12 rejected} +{$fatal $if 12=12 rejected} {$endif} {$if 12<>312} {$info $if 12<>312 is ok} {$else} -{$fatalerror $if 12<>312 rejected} +{$fatal $if 12<>312 rejected} {$endif} {$if 12<=312} {$info $if 12<=312 is ok} {$else} -{$fatalerror $if 12<=312 rejected} +{$fatal $if 12<=312 rejected} {$endif} {$if 12<312} {$info $if 12<312 is ok} {$else} -{$fatalerror $if 12<312 rejected} +{$fatal $if 12<312 rejected} {$endif} {$if a12=a12} {$info $if a12=a12 is ok} {$else} -{$fatalerror $if a12=a12 rejected} +{$fatal $if a12=a12 rejected} {$endif} {$if a12<=z312} {$info $if a12<=z312 is ok} {$else} -{$fatalerror $if a12<=z312 rejected} +{$fatal $if a12<=z312 rejected} {$endif} {$if a12