user.tex 117 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045
  1. %
  2. % $Id$
  3. % This file is part of the FPC documentation.
  4. % Copyright (C) 1997, by Michael Van Canneyt
  5. %
  6. % The FPC documentation is free text; you can redistribute it and/or
  7. % modify it under the terms of the GNU Library General Public License as
  8. % published by the Free Software Foundation; either version 2 of the
  9. % License, or (at your option) any later version.
  10. %
  11. % The FPC Documentation is distributed in the hope that it will be useful,
  12. % but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. % Library General Public License for more details.
  15. %
  16. % You should have received a copy of the GNU Library General Public
  17. % License along with the FPC documentation; see the file COPYING.LIB. If not,
  18. % write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  19. % Boston, MA 02111-1307, USA.
  20. %
  21. \documentclass{report}
  22. \usepackage{a4}
  23. \usepackage{html}
  24. \makeindex
  25. \latex{\usepackage{multicol}}
  26. \latex{\usepackage{fpcman}}
  27. \latex{\usepackage{epsfig}}
  28. \html{\input{fpc-html.tex}}
  29. \newcommand{\remark}[1]{\par$\rightarrow$\textbf{#1}\par}
  30. \newcommand{\olabel}[1]{\label{option:#1}}
  31. % We should change this to something better. See \seef etc.
  32. \newcommand{\seeo}[1]{See \ref{option:#1}}
  33. \begin{document}
  34. \title{Free Pascal :\\ Users' manual}
  35. \docdescription{Users' manual for \fpc, version \fpcversion}
  36. \docversion{1.2}
  37. \date{March 1998}
  38. \author{Micha\"el Van Canneyt\\Florian Kl\"ampfl}
  39. \maketitle
  40. \tableofcontents
  41. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  42. % Introduction
  43. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  44. \chapter{Introduction}
  45. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  46. % About this document
  47. \section{About this document}
  48. This is the user's manual for \fpc . It describes the installation and use of
  49. the \fpc compiler on the different supported platforms.
  50. It does not attempt to give an exhaustive list of all supported commands,
  51. nor a definition of the Pascal language. Look at the
  52. \refref for these things.
  53. For a description of the
  54. possibilities and the inner workings of the compiler, see the
  55. \progref. In the appendices of this document you will find lists of
  56. reserved words and compiler error messages (with descriptions).
  57. This document describes the compiler as it is/functions at the time of
  58. writing. Since the compiler is under continuous development, some of the
  59. things described here may be outdated. In case of doubt, consult the
  60. \file{README} files, distributed with the compiler.
  61. The \file{README} files are, in case of conflict with this manual,
  62. authoritative.
  63. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  64. % About the compiler
  65. \section{About the compiler}
  66. \fpc is a 32-bit compiler for the i386 and m68k processors\footnote{Work is being done
  67. on a port to ALPHA Architecture}. Currently, it supports 2 operating systems:
  68. \begin{itemize}
  69. \item \dos
  70. \item \linux
  71. \end{itemize}
  72. and work is in progress to port it to other platforms (notably, \ostwo and
  73. \windowsnt).
  74. \fpc is designed to be, as much as possible, source compatible with
  75. Turbo Pascal 7.0 and Delphi II (although this goal is not yet attained),
  76. but it also enhances these languages with elements like function overloading.
  77. And, unlike these ancestors, it supports multiple platforms.
  78. It also differs from them in the sense that you cannot use compiled units
  79. from one system for the other.
  80. Also, at the time of writing, there is no Integrated Development Environment
  81. (IDE) available for \fpc. This gap will, hopefully, be filled in the future.
  82. \fpc consists of three parts :
  83. \begin{enumerate}
  84. \item The compiler program itself.
  85. \item The Run-Time Library (RTL).
  86. \item Utility programs and units.
  87. \end{enumerate}
  88. Of these you only need the first two, in order to be able to use the compiler.
  89. In this document, we describe the use of the compiler. The RTL is described in the
  90. \refref.
  91. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  92. % Getting more information.
  93. \section{Getting more information.}
  94. If the documentation doesn't give an answer to your questions,
  95. you can obtain more information on the Internet, on the following addresses:
  96. \begin{itemize}
  97. \item
  98. \htmladdnormallink{http://tfdec1.fys.kuleuven.ac.be/\~{}michael/fpc/fpc.html}
  99. {http://tfdec1.fys.kuleuven.ac.be/\~{}michael/fpc/fpc.html} contains information
  100. on the \linux port of the compiler. It contains also useful mail addresses and
  101. links to other places.
  102. \item
  103. \htmladdnormallink{http://www.brain.uni-freiburg.de/\~{}klaus/fpc/fpc.html}
  104. {http://www.brain.uni-freiburg.de/\~{}klaus/fpc/fpc.html} is the main \fpc information site.
  105. It also contains the instructions for inscribing to the \textit{mailing-list},
  106. another useful source of information.
  107. \end{itemize}
  108. Both places can be used to download the \fpc distribution, although you can
  109. probably find them on other places also.
  110. Finally, if you think something should be added to this manual
  111. (entirely possible), please do not hesitate and contact me at
  112. \htmladdnormallink{[email protected]}{mailto:[email protected]}
  113. .
  114. Let's get on with something useful.
  115. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  116. % Installation
  117. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  118. \chapter{Installing the compiler}
  119. \label{ch:Installation}
  120. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  121. % Before Installation : Requirements
  122. \section{Before Installation : Requirements}
  123. %
  124. % System requirements
  125. %
  126. \subsection{System requirements}
  127. The compiler needs at least the following hardware:
  128. \begin{enumerate}
  129. \item An I386 or higher processor. A coprocessor is not required, although it
  130. will slow down your program's performance if you do floating point calculations.
  131. \item 2 Mb of free memory. Under \dos, if you use DPMI memory management,
  132. such as under Windows, you will need at least 8 Mb.
  133. \item At least 500 Kb. free disk space.
  134. \end{enumerate}
  135. %
  136. %
  137. % Software requirements
  138. \subsection{Software requirements}
  139. \subsubsection{Under DOS}
  140. The \dos distribution contains all the files you need to run the compiler
  141. and compile pascal programs.
  142. \subsubsection{Under Linux}
  143. Under \linux you need to have the following programs installed :
  144. \begin{enumerate}
  145. \item \gnu \file{as}, the \gnu assembler.
  146. \item \gnu \file{ld}, the \gnu linker.
  147. \item Optionally (but highly recommended) : \gnu \file{make}. For easy
  148. recompiling of the compiler and Run-Time Library, this is needed.
  149. \end{enumerate}
  150. Other than that, \fpc should run on almost any I386 \linux system.
  151. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  152. % Installing the compiler.
  153. \section{Installing the compiler.}
  154. The installation of \fpc is easy, but is platform-dependent.
  155. We discuss the process for each platform separately.
  156. %
  157. %
  158. % Installing under DOS
  159. \subsection{Installing under DOS}
  160. \subsubsection{Mandatory installation steps.}
  161. First, you must get the latest distribution files of \fpc. They come as zip
  162. files, which you must unzip first. The distribution zip file contains an
  163. installation program \file{INSTALL.EXE}. You must run this program to install
  164. the compiler.
  165. \html{
  166. The screen of the installation program looks like this:
  167. \htmladdimg{../pics/install.gif}
  168. }
  169. \latex{
  170. The screen of the installation program looks like figure \ref{fig:install}.
  171. \begin{figure}
  172. \caption{The \dos install program screen.}
  173. \label{fig:install}
  174. \epsfig{file=pics/install.eps,width=\textwidth}
  175. \end{figure}
  176. }
  177. The program allows you to select:
  178. \begin{itemize}
  179. \item What components you wish to install. (e.g do you want the sources or
  180. not, do you want docs or not) Items that you didn't download will not
  181. be enabled, i.e. you can't select them.
  182. \item Where you want to install (the default location is \verb|C:\PP|).
  183. \end{itemize}
  184. The installation program generates a batch file which sets some environment
  185. variables : \verb|SET_PP.BAT|. This file is located in the directory where
  186. you installed \fpc. The installation program doesn't modify the
  187. \file{AUTOEXEC.BAT}, since many people (including the authors of \fpc)
  188. don't like this.
  189. You can choose to insert a call to this batch file in your \file{AUTOEXEC.BAT}
  190. file, like this :
  191. \begin{verbatim}
  192. CALL C:\PP\SET_PP.BAT
  193. \end{verbatim}
  194. (This is assuming that you installed \fpc in the default location.)
  195. In order to run \fpc from any directory on your system, you must extend
  196. your path variable to contain the \verb|C:\PP\BIN| directory.
  197. You can choose to do this in your \file{AUTOEXEC.BAT} file, but you can also
  198. insert a statement in the \verb|SET_PP.BAT| file. Whatever the location you
  199. choose, It should look something like this :
  200. \begin{verbatim}
  201. SET PATH=%PATH%;C:\PP\BIN
  202. \end{verbatim}
  203. (Again, assuming that you installed in the default location).
  204. If you want to use the graphic drivers you must modify the
  205. environment variable \var{GO32}. Instructions for doing this can be found
  206. in the documentation of the Graph unit, at the \var{InitGraph} procedure.
  207. \subsubsection{Optional Installation: The coprocessor emulation}
  208. For people who have an older CPU type, without math coprocessor (i387)
  209. it is necessary to install a coprocessor emulation, since \fpc uses the
  210. coprocessor to do all floating point operations.
  211. The installation of the coprocessor emulation is handled by the
  212. installation program (\file{INSTALL.EXE}). However,
  213. the installation program has currently a bug: If you select the
  214. coprocessor emulation the program ignores this and you must do
  215. this by hand. You should change the \var{GO32} environment variable in
  216. the \verb|SET_PP.BAT| file, as follows:
  217. \begin{verbatim}
  218. SET GO32=emu C:\PP\DRIVERS\EMU387
  219. \end{verbatim}
  220. %
  221. % Installing under Linux
  222. %
  223. \subsection{Installing under Linux}
  224. \subsubsection{Mandatory installation steps.}
  225. The \linux distribution of \fpc comes in three forms:
  226. \begin{itemize}
  227. \item a \file{tar.gz} version,
  228. \item a \file{.rpm} (Red Hat Package Manager) version, and
  229. \item a \file{.deb} (debian) version.
  230. \end{itemize}
  231. All of these packages contain a \var{ELF} version of the compiler binaries and
  232. units. the older \var{aout} binaries are no longer distributed, although you
  233. still can use the comiler on an \var{aout} system if you recompile it.
  234. If you use the \file{.rpm} format, installation is limited to
  235. \begin{verbatim}
  236. rpm -i fpc-pascal-XXX.rpm
  237. \end{verbatim}
  238. (\var{XXX} is the version number of the \file{.rpm} file)
  239. If you use debian, installation is limited to
  240. \begin{verbatim}
  241. dpkg -i fpc-XXX.deb
  242. \end{verbatim}
  243. Here again, \var{XXX} is the version number of the \file{.deb} file.
  244. You need root access to install these packages. The \file{.tar} file
  245. allows you to do an installation if you don't have root permissions.
  246. When downloading the \var{.tar} file, installation is more interactive:
  247. This means that you should first untar the file, in some directory where
  248. you have write permission, using the following command:
  249. \begin{verbatim}
  250. tar -xvf fpc.tar
  251. \end{verbatim}
  252. We supposed here that you downloaded the file \file{fpc.tar} somewhere
  253. from the Internet. (The real filename will have some version number in it,
  254. which we omit here for clarity.)
  255. When the file is untarred, you will be left with more archive files, and
  256. an install program: an installation shell script.
  257. To install \fpc, all that you need to do now is give the following command:
  258. \begin{verbatim}
  259. ./install.sh
  260. \end{verbatim}
  261. And then you must answer some questions. They're very simple, they're
  262. mainly concerned with 2 things :
  263. \begin{enumerate}
  264. \item Places where you can install different things.
  265. \item Deciding if you want to install certain components (such as sources
  266. and demo programs).
  267. \end{enumerate}
  268. If you run the installation script as the \var{root} user, you can just accept all installation
  269. defaults. If you don't run as \var{root}, you must take care to supply the
  270. installation program with directory names where you have write permission,
  271. as it will attempt to create the directories you specify.
  272. In principle, you can install it wherever you want, though.
  273. At the end of installation, the installation program will generate a
  274. configuration file for the \fpc compiler which reflects the settings
  275. that you chose. It will install this file in the \file{/etc} directory, (if
  276. you are not installing as \var{root}, this will fail), and in the
  277. directory where you installed the libraries.
  278. If you want the \fpc compiler to use this configuration file, it must be
  279. present in \file{/etc}, or you can set the environment variable
  280. \var{PPC\_CONFIG\_PATH}. Under \file{csh}, you can do this by adding a
  281. \begin{verbatim}
  282. setenv PPC_CONFIG_PATH /usr/lib/ppc/0.99.1
  283. \end{verbatim}
  284. line to your \file{.login} file in your home directory.
  285. (see also the next section)
  286. \subsubsection{Optional configuration steps}
  287. You may wish to set some environment variables. The \linux version of \fpc
  288. recognizes the following variables :
  289. \begin{itemize}
  290. \item \verb|PPC_EXEC_PATH| contains the directory where '\file{as}' and
  291. '\file{ld}' are. (default \file{/usr/bin})
  292. \item \verb|PPC_GCCLIB_PATH| contains the directory where \file{libgcc.a} is (no default)
  293. \item \verb|PPC_CONFIG_PATH| specifies an alternate path to find
  294. \file{ppc386.cfg} (default \file{/etc})
  295. \item \verb|PPC_ERROR_FILE| specifies the path and name of the error-definition file.
  296. (default \file{/usr/lib/ppc/errorE.msg})
  297. \end{itemize}
  298. These locations are, however, set in the sample configuration file which is
  299. built at the end of the installation process, except for the
  300. \verb|PPC_CONFIG_PATH| variable, which you must set if you didn't install
  301. things in the default places.
  302. \subsubsection{finally}
  303. Also distributed in \fpc is a README file. It contains the latest
  304. instructions for installing \fpc, and should always be read first.
  305. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  306. % Testing the compiler
  307. \section{Testing the compiler}
  308. After the installation is completed and the environment variables are
  309. set as described above, your first program can be compiled.
  310. Included in the \fpc distribution are some demonstration programs,
  311. showing what the compiler can do.
  312. You can test if the compiler functions correctly by trying to compile
  313. these programs.
  314. The compiler is called
  315. \begin{itemize}
  316. \item \file{PPC386.EXE} under \dos, and
  317. \item \file{ppc386} under \linux
  318. \end{itemize}
  319. To compile a program (e.g \verb|demo\hello.pp|) simply type :
  320. \begin{verbatim}
  321. ppc386 hello
  322. \end{verbatim}
  323. at the command prompt.
  324. If you got no error messages, the compiler has generated an executable
  325. called \file{hello} (no extension) under \linux, and a file \file{hello.exe}
  326. under \dos.
  327. To execute the program, simply type :
  328. \begin{verbatim}
  329. hello
  330. \end{verbatim}
  331. If all went well, you should see the following friendly greeting:
  332. \begin{verbatim}
  333. Hello world
  334. \end{verbatim}
  335. In the \dos case, this friendly greeting may be preceded by some ugly
  336. message from the \file{GO32} extender program. This unfriendly behavior can
  337. be switched off by setting the \file{GO32} environment variable.
  338. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  339. % Usage
  340. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  341. \chapter{Compiler usage}
  342. \label{ch:Usage}
  343. Here we describe the essentials to compile a program and a unit.
  344. We also describe how to make a stand-alone executable of the
  345. compiled program under \dos. For more advanced uses of the compiler,
  346. see the section on configuring the compiler, and the
  347. \progref.
  348. The examples in this section suppose that you have a \file{ppc386.cfg} which
  349. is set up correctly, and which contains at least the path setting for the
  350. RTL units. In principle this file is generated by the installation program.
  351. You may have to check that it is in the correct place (see section
  352. \ref{se:config_file} for more information on this).
  353. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  354. % Compiling a program
  355. \section{Compiling a program}
  356. Compiling a program is very simple. Assuming that you have a program source
  357. in the file \file{prog.pp}, you can compile this with the following command:
  358. \begin{verbatim}
  359. ppc386 [options] prog.pp
  360. \end{verbatim}
  361. The square brackets [] indicate that what is between them is optional.
  362. If your program file has the \file{.pp} or \file{.pas} extension,
  363. you can omit this on the command line, e.g. in the previous example you
  364. could have typed:
  365. \begin{verbatim}
  366. ppc386 [options] prog
  367. \end{verbatim}
  368. If all went well, the compiler will produce an executable, or, for version 1
  369. of the \dos extender, a file which can be converted to an executable.
  370. Under \linux and version 2 of the \dos extender, the file you obtained is
  371. the executable. You can execute it straight away, you don't need to do
  372. anything else. Under \dos,
  373. additional processing is required. See the section on creating an
  374. executable.
  375. You will notice that there is also anothe file in your directory, with
  376. extensions \file{.o}. This contains, the object file for your program.
  377. If you compiled a program, you can delete the object file (\file{.o}),
  378. but not if you compiled a unit.
  379. Then the object file contains the code of the unit, and will be
  380. linked in any program that uses the unit you compiled, so you shpuldn't
  381. remove it.
  382. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  383. % Compiling a unit
  384. \section{Compiling a unit}
  385. Compiling a unit is not essentially different from compiling a program.
  386. The difference is mainly that the linker isn't called in this case.
  387. To compile a unit in the file \file{foo.pp}, just type :
  388. \begin{verbatim}
  389. ppc386 foo
  390. \end{verbatim}
  391. Recall the remark about file extensions in the previous section.
  392. When all went well, you will be left with 2 (two) unit files:
  393. \begin{enumerate}
  394. \item \file{foo.ppu} This is the file describing the unit you just
  395. compiled.
  396. \item \file{foo.o} This file contains the actual code of the unit.
  397. This file will eventually end up in the executables.
  398. \end{enumerate}
  399. Both files are needed if you plan to use the unit for some programs.
  400. So don't delete them. If you want to distribute the unit, you must
  401. provide both the \file{.ppu} and \file{.o} file. One is useless without the
  402. other.
  403. {\em Remark:}
  404. Under \linux, a unit source file {\em must} have a lowercase filename.
  405. Since Pascal is case independent, you can specify the names of units in the
  406. \var{uses} clause in either case. To get a unique filename, the \fpc compiler
  407. changes the name of the unit to all lowercase when looking for unit files.
  408. The compiler produces lowercase files, so your unit will be found, even if
  409. your source file has uppercase letters in it. Only when the compiler tries to
  410. recompile the unit, it will not find your source because of the uppercase
  411. letters.
  412. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  413. % Creating an executable for GO32V1, PMODE/DJ targets
  414. \section{Creating an executable for GO32V1 and PMODE/DJ targets}
  415. This section applies only to \dos users. \linux users can skip this
  416. section (unless they're cross-compiling)
  417. %
  418. % GO32V1
  419. %
  420. \subsection{GO32V1}
  421. When compiling under \dos, GO32V2 is the default target. However, if you use
  422. go32V1 (using the \var{-TGO32V1} switch), the
  423. compilation process leaves you with a file which you cannot execute right away.
  424. There are 2 things you can do when compiling has finished.
  425. The first thing is to use the \dos extender from D.J. Delorie to execute
  426. your program :
  427. \begin{verbatim}
  428. go32 prog
  429. \end{verbatim}
  430. This is fine for testing, but if you want to use a program regularly, it
  431. would be easier if you could just type the program name, i.e.
  432. \begin{verbatim}
  433. prog
  434. \end{verbatim}
  435. This can be accomplished by making a \dos executable of your compiled program.
  436. There two ways to create a \dos executable (under \dos only):
  437. \begin{enumerate}
  438. \item if the \file{GO32.EXE} is already
  439. installed on the computers where the program should run, you must
  440. only copy a program called \file{STUB.EXE} at the begin of
  441. the AOUT file. This is accomplished with the \file{AOUT2EXE.EXE} program.
  442. which comes with the compiler:
  443. \begin{verbatim}
  444. AOUT2EXE PROG
  445. \end{verbatim}
  446. and you get a \dos executable which loads the \file{GO32.EXE} automatically.
  447. the \file{GO32.EXE} executable must be in current directory or be
  448. in a directory in the \var{PATH} variable.
  449. \item
  450. The second way to create a \dos executable is to put
  451. \file{GO32.EXE} at the beginning of the \file{AOUT} file. To do this, at the
  452. command prompt, type :
  453. \begin{verbatim}
  454. COPY /B GO32.EXE+PROG PROG.EXE
  455. \end{verbatim}
  456. (assuming \fpc created a file called \file{PROG}, of course.)
  457. This becomes then a stand-alone executable for \dos, which doesn't need the
  458. \file{GO32.EXE} on the machine where it should run.
  459. \end{enumerate}
  460. %
  461. %
  462. % PMODE/DJ
  463. \subsection{PMODE/DJ}
  464. You can also use the PMODE/DJ extender to run your \fpc applications.
  465. To make an executable which works with the PMODE extender, you can simply
  466. create an GO32V2 executable (the default), and then convert it to a PMODE
  467. executable with the following two extra commands:
  468. \begin{enumerate}
  469. \item First, strip the GO32V2 header of the executable:
  470. \begin{verbatim}
  471. EXE2COFF PROG.EXE
  472. \end{verbatim}
  473. (we suppose that \file{PROG.EXE} is the program generated by the compilation
  474. process.
  475. \item Secondly, add the PMODE stub:
  476. \begin{verbatim}
  477. COPY /B PMODSTUB.EXE+PROG PROG.EXE
  478. \end{verbatim}
  479. If the \file{PMODSTUB.EXE} file isn't in your local directory, you need to
  480. supply the whole path to it.
  481. \end{enumerate}
  482. That's it. No additional steps are needed to create a PMODE extender
  483. executable.
  484. Be aware, though, that the PMODE extender doesn't support virtual memory, so
  485. if you're short on memory, you may run unto trouble. Also, officially there
  486. is not support for the PMODE/DJ extender. It just happens that the compiler
  487. and some of the programs it generates, run under this extender too.
  488. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  489. % Reducing the size of your program
  490. \section{Reducing the size of your program}
  491. When you created your program, it is possible to reduce its size. This
  492. is possible, because the compiler leaves a lot of information in the
  493. program which, strictly speaking, isn't required for the execution of
  494. it. The surplus of information can be removed with a small program
  495. called \file{strip}. It comes with the \var{GO32} development
  496. environment under \dos, and is standard on \linux machines where you can
  497. do development. The usage is simple. Just type
  498. \begin{verbatim}
  499. strip prog
  500. \end{verbatim}
  501. On the command line, and the \file{strip} program will remove all unnecessary
  502. information from your program. This can lead to size reductions of up to
  503. 30 \%.
  504. You can use the \var{-Xs} switch to let the compiler do this stripping
  505. automatically.
  506. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  507. % Problems
  508. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  509. \chapter{Compiling problems}
  510. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  511. % General problems
  512. \section{General problems}
  513. \begin{itemize}
  514. \item \textbf{IO-error -2 at ...} : Under \linux you can get this message at
  515. compiler startup. It means typically that the compiler doesn't find the
  516. error definitions file. You can correct this mistake with the \var{-Fr}
  517. option under \linux. (\seeo{Fr})
  518. \item \textbf {Error : File not found : xxx} This typically happens when
  519. your unit path isn't set correctly. Remember that the compiler looks for
  520. units only in the current directory, and in the directory where the compiler
  521. itself is. If you want it to look somewhere else too, you must explicitly
  522. tell it to do so using the \var{-Up} option (\seeo{Up}).
  523. \end{itemize}
  524. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  525. % Problems you may encounter under DOS
  526. \section{Problems you may encounter under DOS}
  527. \begin{itemize}
  528. \item \textbf{No space in environment}.\\
  529. An error message like this can occur, if you call
  530. \verb|SET_PP.BAT| in the \file{AUTOEXEC.BAT}.\\
  531. To solve this problem, you must extend your environment memory.
  532. To do this, search a line in the \file{CONFIG.SYS} like
  533. \begin{verbatim}
  534. SHELL=C:\DOS\COMMAND.COM
  535. \end{verbatim}
  536. and change it to the following:
  537. \begin{verbatim}
  538. SHELL=C:\DOS\COMMAND.COM /E:1024
  539. \end{verbatim}
  540. You may just need to specify a higher value, if this parameter is already set.
  541. \item \textbf{ Coprocessor missing}\\
  542. If the compiler writes
  543. a message that there is no coprocessor, install
  544. the coprocessor emulation.
  545. \item \textbf{Not enough DPMI memory}\\
  546. If you want to use the compiler with \var{DPMI} you must have at least
  547. 7-8 MB free \var{DPMI} memory.
  548. \end{itemize}
  549. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  550. % Configuration.
  551. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  552. \chapter{Compiler configuration}
  553. \label{ch:CompilerConfiguration}
  554. The output of the compiler can be controlled in many ways. This can be done
  555. essentially in two distinct ways:
  556. \begin{itemize}
  557. \item Using command-line options.
  558. \item Using the configuration file: \file{ppc386.cfg}.
  559. \end{itemize}
  560. The compiler first reads the configuration file. Only then the command line
  561. options are checked. This creates the possibility to set some basic options
  562. in the configuration file, and at the same time you can still set some
  563. specific options when compiling some unit or program. First we list the
  564. command line options, and then we explain how to specify the command
  565. line options in the configuration file. When reading this, keep in mind
  566. that the options are case sensitive. While this is customary for \linux, it
  567. isn't under \dos.
  568. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  569. % Using the command-line options
  570. \section{Using the command-line options}
  571. The available options are listed by category:
  572. %
  573. % General options
  574. %
  575. \subsection{General options}
  576. \begin{description}
  577. \item[-h] if you specify this option, the compiler outputs a list of all options,
  578. and exits after that.
  579. \olabel{h}
  580. \item[-?] idem as \var{-h}.
  581. \item[-i] This option tells the compiler to print the copyright information.
  582. \olabel{i}
  583. \item[-l] This option tells the compiler to print the \fpc logo on standard
  584. output. It also gives you the \fpc version number.
  585. \olabel{l}
  586. \item[-Lx] Set the language the compiler uses for its messages.
  587. \olabel{L}
  588. \var{x} can be one of the following:
  589. \begin{itemize}
  590. \item \textbf{D} : Use German.
  591. \item \textbf{E} : Use English.
  592. \end{itemize}
  593. \item [-n] Tells the compiler not to read the configuration file.
  594. \olabel{n}
  595. \end{description}
  596. %
  597. % Options for getting feedback
  598. %
  599. \subsection{Options for getting feedback}
  600. \begin{description}
  601. \item[-vxxx] Be verbose. \var{xxx} is a combination of the following :
  602. \olabel{v}
  603. \begin{itemize}
  604. \item \var{e} : Tells the compiler to show only errors. This option is on by default.
  605. \item \var{i} : Tells the compiler to show some general information.
  606. \item \var{w} : Tells the compiler to issue warnings.
  607. \item \var{n} : Tells the compiler to issue notes.
  608. \item \var{h} : Tells the compiler to issue hints.
  609. \item \var{l} : Tells the compiler to show the line numbers as it processes a
  610. file. Numbers are shown per 100.
  611. \item \var{u} : Tells the compiler to print the names of the files it opens.
  612. \item \var{t} : Tells the compiler to print the names of the files it tries
  613. to open.
  614. \item \var{p} : Tells the compiler to print the names of procedures and
  615. functions as it is processing them.
  616. \item \var{c} : Tells the compiler to warn you when it processes a
  617. conditional.
  618. \item \var{m} : Tells the compiler to write which macros are defined.
  619. \item \var{d} : Tells the compiler to write other debugging info.
  620. \item \var{a} : Tells the compiler to write all possible info. (this is the
  621. same as spcifying all options)
  622. \item \var{0} : Tells the compiler to write no messages. This is useful when
  623. you want to override the default setting in the configuration file.
  624. \end{itemize}
  625. \end{description}
  626. %
  627. % Options concerning files and directories
  628. %
  629. \subsection{Options concerning files and directories}
  630. \begin{description}
  631. \item [-exxx] (\linux only) \file{xxx} specifies the directory where the
  632. compiler can find the executables \file{as} (the assembler) and \file{ld} (the
  633. compiler).
  634. \olabel{e}
  635. \item [-Fexxx] This option tells the compiler to write errors, etc. to
  636. the file in \file{xxx}.
  637. \olabel{Fe}
  638. \item [-Fgxxx] (\linux only) \file{xxx} specifies the path where the compiler
  639. can find the \gnu C library.
  640. \olabel{Fg}
  641. \item [-Fixxx] adds \var{xxx} to the path where the compiler searches for
  642. its include files.
  643. \olabel{Fi}
  644. \item [-Flxxx] Adds \var{xxx} to the library searching path, and is passed
  645. to the linker.
  646. \olabel{Fl}
  647. \item [-Frxxx] (\linux only) \file{xxx} specifies the path where the
  648. compiler can find the error-definitions file.
  649. \olabel{Fr}
  650. \item [-Fuxxx] Idem as \var{-Up}.
  651. \olabel{Fu}
  652. \item [-P] uses pipes instead of files when assembling. This may speed up
  653. the compiler on \ostwo and \linux. Only with assemblers (such as \gnu
  654. \file{as}) that support piping..
  655. \item [-Upxxx] \olabel{Up} Tells the compiler to add \file{xxx} to the path where to find
  656. units. \\
  657. By default, the compiler only searches for units in the current directory
  658. and the directory where the compiler itself resides. This option tells the
  659. compiler also to look in the directory \file{xxx}.
  660. \end{description}
  661. % Options controlling the kind of output.
  662. \subsection{Options controlling the kind of output.}
  663. for more information on these options, see also \progref
  664. \begin{description}
  665. \item [-a] \olabel{a} Tells the compiler not to delete the assembler file.
  666. This also counts for the (possibly) generated batch script.
  667. \item [-Axxx] \olabel{A}specifies what kind of assembler should be generated . Here
  668. \var{xxx} is one of the following :
  669. \begin{itemize}
  670. \item \textbf{att} : AT\&T assembler.
  671. \item \textbf{o} : A unix .o (object) file.
  672. \item \textbf{obj} : A OMF file for using the NASM assembler.
  673. \item \textbf{nasm} : a coff file using the NASM assembler.
  674. \item \textbf{masm} : An assembler file for the Microsoft/Borland/Watcom assembler.
  675. \end{itemize}
  676. \item [-CD] Force dynamic linking.
  677. \item [-Chxxx] \olabel {Ch} Reserves \var{xxx} bytes heap.
  678. \item [-Ci] \olabel{Ci} Generate Input/output checking code.
  679. \item [-Cn] \olabel{Cn} Omit the linking stage.
  680. \item [-Co] \olabel{Co} Generate Integer overflow checking code.
  681. \item [-Cr] \olabel{Cr} Generate Range checking code.
  682. \item [-Csxxx] \olabel{Cs} Set stack size to \var{xxx}. (\ostwo only).
  683. \item [CS] \olabel{CS} Statically link your program/unit.
  684. \item [-Ct] \olabel{Ct} generate stack checking code.
  685. \item [-dxxx] \olabel{d} Define the symbol name \var{xxx}. This can be used
  686. to conditionally compile parts of your code.
  687. \item {-E} \olabel{E} Same as \var{-Cn}.
  688. \item [-g] \olabel{g} Generate debugging information for debugging with
  689. \file{gdb}.
  690. \item [-gp] \olabel{gp} Generate profiler code for \file{gprof}.
  691. \item[-On] \olabel{O} optimize the compiler's output; \var{n} can have one
  692. of the following values :
  693. \begin{description}
  694. \item[a] simple optimizations
  695. \item[g] optimize for size
  696. \item[G] optimize for time
  697. \item[x] optimize maximum
  698. \item[z] uncertain optimizations
  699. \item[2] optimize for Pentium II (tm)
  700. \item[3] optimize for i386
  701. \item[4] optimize for i486
  702. \item[5] optimize for Pentium (tm)
  703. \item[6] optimizations for PentiumPro (tm)
  704. \end{description}
  705. The exact effect of these effects can be found in the appendices of the
  706. \progref.
  707. \item [-oxxx] Tells the compiler to use \var{xxx} as the name of the output
  708. file (executable). Only with programs.
  709. \item [-pg] Tells the compiler to issue code for profiling support.
  710. \item [-s] \olabel{s} Tells the compiler not to call the assembler and linker.
  711. Instead, the compiler writes a script, \file{PPAS.BAT} under \dos, or
  712. \file{ppas.sh} under \linux, which can then be executed to produce an
  713. executable.
  714. \item[-Txxx] \olabel{T}Specifies the target operating system. \var{xxx} can be one of
  715. the following:
  716. \begin{itemize}
  717. \item \textbf{DOS} : \dos and the DJ DELORIE extender.
  718. \item \textbf{OS2} : OS/2 (2.x) (this is still under development).
  719. \item \textbf{LINUX} : \linux.
  720. \item \textbf{WIN32} : Windows 32 bit (this is still under development).
  721. \item \textbf{GO32V2} : \dos and version 2 of the DJ DELORIE extender.
  722. \end{itemize}
  723. \item [-Uld] \olabel{Uld} make dynamic library from unit.
  724. \item [-Uls] \olabel{Uls} make static library from unit.
  725. \item [-uxxx] \olabel{U} Undefine symbol \var{xxx}.
  726. \item [-Xx] \olabel{X} executable options. This tells the compiler what
  727. kind of \linux executable should be generated. the parameter \var{x}
  728. can be one of the following:
  729. \begin{itemize}
  730. % \item \textbf{e} : (\linux only) Create an \file{ELF} executable (default).
  731. \item \textbf{c} : (\linux only) Link with the C library. You should only use this when
  732. you start to port \fpc to another operating system.
  733. \item \textbf{s} : (\dos only) Strip the symbols from the executable.
  734. \end{itemize}
  735. \end{description}
  736. %
  737. %
  738. % Options concerning the sources (language options)
  739. \subsection{Options concerning the sources (language options)}
  740. for more information on these options, see also \progref
  741. \begin{description}
  742. \item [-Rxxx] \olabel{R} Specifies what assembler you use in your \var{asm} assembler code
  743. blocks. Here \var{xxx} is one of the following:
  744. \begin{description}
  745. \item [att\ ] \var{asm} blocks contain AT\&T assembler.
  746. \item [intel] \var{asm} blocks contain Intel assembler.
  747. \item [direct] \var{asm} blocks should be copied as-is in the assembler
  748. file.
  749. \end{description}
  750. \item [-S2] \olabel{Stwo} Switch on Delphi 2 extensions.
  751. \item [-Sc] \olabel{Sc} Support C-style operators, i.e. \var{*=, +=, /= and
  752. -=}.
  753. \item [-Se] \olabel{Se} The compiler stops after the first error. Normally,
  754. the compiler tries to continue compiling after an error, until 50 errors are
  755. reached, or a fatal error is reachd, and then it stops. With this switch,
  756. the compiler will stop after the first error.
  757. \item [-Sg] \olabel{Sg} Support the \var{label} and \var{goto} commands.
  758. \item [-Si] \olabel{Si} Support \var{C++} style INLINE.
  759. \item [-Sm] \olabel{Sm} Support C-style macros.
  760. \item [-So] \olabel{So} Try to be Borland TP compatible (no function
  761. overloading etc.).
  762. \item [-Ss] \olabel{Ss} The name of constructors must be \var{init}, and the
  763. name of destructors should be \var{done}.
  764. \item [-St] \olabel{St} Allow the \var{static} keyword in objects.
  765. \item [-Un] \olabel{Un} Do not check the unit name. (Normally, the unit name
  766. is the same as the filename. This option allows both to be different.)
  767. \item [-Us] \olabel{Us} Compile a system unit. This option causes the
  768. compiler to define only some very basic types.
  769. \end{description}
  770. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  771. % Using the configuration file
  772. \section{Using the configuration file}
  773. \label{se:config_file}
  774. Using the configuration file \file{ppc386.cfg} is an alternative to command
  775. line options. When a configuration file is found, it is read, and the lines
  776. in it are treated like you typed them on the command line. They are treated
  777. before the options that you type on the command line.
  778. You can specify comments in the configuration file with the \var{\#} sign.
  779. Everything from the \var{\#} on will be ignored.
  780. The compiler looks for the \file{ppc386.cfg} file in the following places :
  781. \begin{enumerate}
  782. \item The current directory.
  783. \item Under \dos, the directory where the compiler is. Under \linux,
  784. the compiler looks in the \file{/etc} directory
  785. \item if specified, the directory in the \var{PPC\_CONFIG\_PATH} environment variable.
  786. \end{enumerate}
  787. When the compiler has finished reading the configuration file, it continues
  788. to treat the command line options.
  789. One of the command-line options allows you to specify a second configuration
  790. file: Specifying \file{@foo} on the command line will open file \file{foo},
  791. and read further options from there. When the compiler has finished reading
  792. this file, it continues to process the command line.
  793. An important feature in the configuration file is that you can specify
  794. sections. They behave much like conditional defines.
  795. Suppose the following configuration file (named \file{myconf})
  796. \begin{verbatim}
  797. -a
  798. #section first
  799. -Up/some_path
  800. #section second
  801. -Up/other_path.
  802. \end{verbatim}
  803. When you invoke the compiler as follows:
  804. \begin{verbatim}
  805. ppc386 -dfirst @myconf foo.pp
  806. \end{verbatim}
  807. then the compiler will read the part of the configuration file coming before
  808. the line containing \var{\#section second}. As a result the unit search path will be set
  809. to \file{/some\_path}.
  810. If, on the other hand, you invoke the compiler as
  811. \begin{verbatim}
  812. ppc386 -dsecond @myconf foo.pp
  813. \end{verbatim}
  814. Then the configuration file will be read as if the part between
  815. \var{\#section first} and \var{\#section second} didn't exist, resulting
  816. in a unit search path of \file{/other\_path}.
  817. If you put a \var{\#section common} on a line, everything that follows this
  818. keyword will be read, whatever the defined constants.
  819. In short, the \var{\#define} keywords act as conditionals.
  820. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  821. % Porting.
  822. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  823. \chapter{Porting Turbo Pascal Code}
  824. \fpc was designed to resemble Turbo Pascal as closely as possible. There
  825. are, of course, restrictions. Some of these are due to the fact that \fpc is
  826. a 32-bit compiler. Other restrictions result from the fact that \fpc works
  827. on more than one operating system.
  828. In general we can say that if you keep your program code close to ANSI
  829. Pascal, you will have no problems porting from Turbo Pascal, or even Delphi, to
  830. \fpc. To a large extent, the constructs defined by Turbo Pascal are
  831. supported.
  832. In the following sections we will list the Turbo Pascal constructs which are
  833. not supported in \fpc, and we will list in what ways \fpc extends the Turbo
  834. Pascal language.
  835. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  836. % Things that will not work
  837. \section{Things that will not work}
  838. Here we give a list of things which are defined/allowed in Turbo Pascal, but
  839. which are not supported by \fpc. Where possible, we indicate the reason.
  840. \begin{enumerate}
  841. \item Parameter lists of previously defined functions and procedures must
  842. match exactly. The reason for this is the function overloading mechanism of
  843. \fpc. (however, \seeo{So})
  844. \item \var {(* ... *)} as comment delimiters are not allowed in versions
  845. older than 0.9.1. This can easily be remedied with a grown-up editor.
  846. \item The \var{MEM, MEMW, MEML} and \var{PORT} variables for memory and port
  847. access are not available. This is due to the operating system. Under
  848. \dos, the extender unit (\file {GO32.PPU} provides functions to remedy this.
  849. \item \var{PROTECTED, PUBLIC, TRY, THROW, EXCEPTION} are reserved words.
  850. This means you cannot create procedures or variables with the same name.
  851. While they are not reserved words in Turbo Pascal, they are in Delphi.
  852. \item The reserved words \var{FAR, NEAR} are ignored. This is
  853. because \fpc is a 32 bit compiler, so they're obsolete.
  854. \item \var{INTERRUPT} only will work on a DOS machine.
  855. \item Boolean expressions are only evaluated until their result is completely
  856. determined. The rest of the expression will be ignored.
  857. \item At the moment of writing, the assembler syntax used in \fpc is \var{AT\&T}
  858. assembler syntax. This is mainly because \fpc uses \gnu \var{as}.
  859. \item Turbo Vision is not available.
  860. \item The 'overlay' unit is not available. It also isn't necessary, since
  861. \fpc is a 32 bit compiler, so program size shouldn't be a point.
  862. \item There are more reserved words. (see appendix \ref{ch:reserved} for a
  863. list of all reserved words.)
  864. \item The command-line parameters of the compiler are different.
  865. \item The compiler switches behave different.
  866. \item Units are not binary compatible.
  867. \end{enumerate}
  868. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  869. % Things which are extra
  870. \section{Things which are extra}
  871. Here we give a list of things which are possible in \fpc, but which
  872. didn't exist in Turbo Pascal or Delphi.
  873. \begin{enumerate}
  874. \item There are more reserved words. (see appendix \ref{ch:reserved} for a
  875. list of all reserved words.)
  876. \item Functions can also return complex types, such as records and arrays.
  877. \item You can handle function results in the function itself, as a variable.
  878. Example
  879. \begin{verbatim}
  880. function a : longint;
  881. begin
  882. a:=12;
  883. while a>4 do
  884. begin
  885. {...}
  886. end;
  887. end;
  888. \end{verbatim}
  889. The example above would work with TP, but the compiler would assume
  890. that the \var{a>4} is a recursive call. To do a recursive call in
  891. this you must append \var{()} behind the function name:
  892. \begin{verbatim}
  893. function a : longint;
  894. begin
  895. a:=12;
  896. { this is the recursive call }
  897. if a()>4 then
  898. begin
  899. {...}
  900. end;
  901. end;
  902. \end{verbatim}
  903. \item There is partial support of Delphi constructs. (see the \progref for
  904. more information on this).
  905. \item The \var{exit} call accepts a return value for functions.
  906. \begin{verbatim}
  907. function a : longint;
  908. begin
  909. a:=12;
  910. if a>4 then
  911. begin
  912. exit(a*67); {function result upon exit is a*67 }
  913. end;
  914. end;
  915. \end{verbatim}
  916. \item \fpc supports function overloading. That is, you can define many
  917. functions with the same name, but with different arguments. For example:
  918. \begin{verbatim}
  919. procedure DoSomething (a : longint);
  920. begin
  921. {...}
  922. end;
  923. procedure DoSomething (a : real);
  924. begin
  925. {...}
  926. end;
  927. \end{verbatim}
  928. You can then call procedure \var{DoSomething} with an argument of type
  929. \var{Longint} or \var{Real}.\\
  930. This feature has the consequence that a previously declared function must
  931. always be defined with the header completely the same:
  932. \begin{verbatim}
  933. procedure x (v : longint); forward;
  934. {...}
  935. procedure x;{ This will overload the previously declared x}
  936. begin
  937. {...}
  938. end;
  939. \end{verbatim}
  940. This construction will generate a compiler error, because the compiler
  941. didn't find a definition of \var{procedure x (v : longint);}. Instead you
  942. should define your procedure x as:
  943. \begin{verbatim}
  944. procedure x (v : longint);
  945. { This correctly defines the previously declared x}
  946. begin
  947. {...}
  948. end;
  949. \end{verbatim}
  950. \end{enumerate}
  951. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  952. % Turbo Pascal compatibility mode
  953. \section{Turbo Pascal compatibility mode}
  954. When you compile a program with the \var{-So} switch, the compiler will
  955. attempt to mimic the Turbo Pascal compiler in the following ways:
  956. \begin{itemize}
  957. \item Assigning a procedural variable doesn't require a @ operator. One of
  958. the differences between Turbo Pascal and \fpc is that the latter requires
  959. you to specify an address operator when assigning a value to a procedural
  960. variable. In Turbo Pascal compatibility mode, this is not required.
  961. \item Procedure overloading is disabled.
  962. \item Forward defined procedures don't need the full parameter list when
  963. they are defined. Due to the procedure overloading feature of \fpc, you must
  964. always specify the parameter list of a function when you define it, even
  965. when it was declared earlier with \var{Forward}. In Turbo Pascal
  966. compatibility mode, there is no function overloading, hence you can omit the
  967. parameter list:
  968. \begin{verbatim}
  969. Procedure a (L : Longint); Forward;
  970. ...
  971. Procedure a ; { No need to repeat the (L : Longint) }
  972. begin
  973. ...
  974. end;
  975. \end{verbatim}
  976. \item recursive function calls are handled dfferently. Consider the
  977. following example :
  978. \begin{verbatim}
  979. Function expr : Longint;
  980. begin
  981. ...
  982. Expr:=L:
  983. Writeln (Expr);
  984. ...
  985. end;
  986. \end{verbatim}
  987. In Turbo Pascal compatibility mode, the function will be called recursively
  988. when the \var{writeln} statement is processed. In \fpc, the function result
  989. will be printed. In order to call the function recusively under \fpc, you
  990. need to implement it as follows :
  991. \begin{verbatim}
  992. Function expr : Longint;
  993. begin
  994. ...
  995. Expr:=L:
  996. Writeln (Expr());
  997. ...
  998. end;
  999. \end{verbatim}
  1000. \item Any text after the final \var{End.} statement is ignored. Normally,
  1001. this text is processed too.
  1002. \item You cannot assign procedural variables to void pointers.
  1003. \item The @ operator is typed when applied on procedures.
  1004. \item You cannot nest comments.
  1005. \end{itemize}
  1006. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1007. % Utilities.
  1008. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1009. \chapter{Utilities and units that come with Free Pascal}
  1010. \label{ch:Utilities}
  1011. Besides the compiler and the Run-Time Library, \fpc comes with some utility
  1012. programs and units. Here we list these programs and units.
  1013. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1014. % Supplied programs
  1015. \section{Supplied programs}
  1016. \begin{itemize}
  1017. \item \file{dumppu} is a program which shows the contents of a \fpc unit. It
  1018. comes in source form, and must be compiled before you can use it. Once
  1019. compiled, you can just issue the following command
  1020. \begin{verbatim}
  1021. dumppu foo.ppu
  1022. \end{verbatim}
  1023. to display the contents of the \file{foo.ppu} unit.
  1024. \item Also distributed with Free Pascal comes a series of demonstration programs.
  1025. These programs have no other purpose than demonstrating the capabilities of
  1026. \fpc. They are located in the \file{demo} directory of the sources.
  1027. \item All example programs of the documentation are available. Check out the
  1028. directories that end on \file{ex} in the documentation sources. There you
  1029. will find all example sources.
  1030. \item \file{ppumove} is a program to make shared or static libraries from
  1031. units. It should be distributed in binary form along with the compiler.
  1032. \end{itemize}
  1033. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1034. % Supplied units
  1035. \section{Supplied units}
  1036. Here we list the units that come with the \fpc distribution. Since there is
  1037. a difference in the supplied units per operating system, we list them
  1038. separately per system. They are documented in the \unitsref.
  1039. %
  1040. % Under DOS
  1041. %
  1042. \subsection{Under DOS}
  1043. \begin{itemize}
  1044. \item [strings] This unit provides basic
  1045. string handling routines for the \var{pchar} type, comparable to similar
  1046. routines in standard \var{C} libraries.
  1047. \item [objects] This unit provides basic
  1048. routines for handling objects.
  1049. \item [dos] This unit provides basic routines for
  1050. accessing the operating system \dos. It provides almost the same
  1051. functionality as the Turbo Pascal unit.
  1052. \item [printer] This unit provides all you
  1053. need for rudimentary access to the printer.
  1054. \item [getopts] This unit gives you the
  1055. \gnu \var{getopts} command-line arguments handling mechanism.
  1056. It also supports long options.
  1057. \item [crt] This unit provides basic screen
  1058. handling routines. It provides the same functionality as the Turbo Pascal \var{CRT}
  1059. unit.
  1060. \item [graph] This unit provides basic graphics
  1061. handling, with routines to draw lines on the screen, display texts etc. It
  1062. provides the same functions as the Turbo Pascal unit.
  1063. \item [go32] This unit provides access to possibilities of the \var{GO32}
  1064. \dos extender.
  1065. \item [emu387] This unit provides support for the coprocessor emulator.
  1066. \item [mmx] This unit provides support for \var{mmx} extensions in your
  1067. code.
  1068. \end{itemize}
  1069. %
  1070. % Under Linux
  1071. %
  1072. \subsection{Under Linux}
  1073. \begin{itemize}
  1074. \item [strings] This unit provides basic
  1075. string handling routines for the \var{PChar} type, comparable to similar
  1076. routines in standard \var{C} libraries.
  1077. \item [objects] This unit provides basic
  1078. routines for handling objects.
  1079. \item [crt] This unit provides basic screen
  1080. handling routines. It provides the same functionality Turbo Pascal \var{CRT}
  1081. unit. It works on any terminal which supports the \var{vt100} escape
  1082. sequences.
  1083. \item [dos] This unit provides an emulation of the
  1084. same unit under \dos. It is intended primarily for easy porting of Pascal
  1085. programs from \dos to \linux. For good performance, however, it is
  1086. recommended to use the \var{linux} unit.
  1087. \item [linux] This unit provides access to the
  1088. \linux operating system. It provides most file and I/O handling routines
  1089. that you may need. It implements most of the standard \var{C} library constructs
  1090. that you will find on a Unix system. If you do a lot of disk/file
  1091. operations, the use of this unit is recommended over the one you use under
  1092. Dos.
  1093. \item [printer] This unit provides an
  1094. interface to the standard Unix printing mechanism.
  1095. \item [getopts] This unit gives you the
  1096. \gnu \var{getopts} command-line arguments handling mechanism.
  1097. It also supports long options.
  1098. \item [mmx] This unit provides support for \var{mmx} extensions in your
  1099. code.
  1100. \item [sockets] This unit gives you access to sockets and TCP/IP
  1101. programming.
  1102. \end{itemize}
  1103. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1104. % Debugging
  1105. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1106. \chapter{Debugging your Programs}
  1107. \fpc supports debug information for the \gnu debugger \var{gdb}.
  1108. This chapter describes shortly how to use this feature. It doesn't attempt
  1109. to describe completely the \gnu debugger, however.
  1110. For more information on the workings of the \gnu debugger, see the \var{gdb}
  1111. users' guide.
  1112. \fpc also suports \var{gprof}, the \gnu profiler, see section \ref{se:gprof}
  1113. for more information on profiling.
  1114. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1115. % Compiling your program with debugger support
  1116. \section{Compiling your program with debugger support}
  1117. First of all, you must be sure that the compiler is compiled with debugging
  1118. support. Unfortunately, there is no way to check this at run time, except by
  1119. trying to compile a program with debugging support.
  1120. To compile a program with debugging support, just specify the \var{-g}
  1121. option on the command-line, as follows:
  1122. \begin{verbatim}
  1123. ppc386 -g hello.pp
  1124. \end{verbatim}
  1125. This will generate debugging information in the executable from your
  1126. program. You will notice that the size of the executable increases
  1127. substantially because of this\footnote{A good reason not to include debug
  1128. information in an executable you plan to distribute.}.
  1129. Note that the above will only generate debug information {\var for the code
  1130. that has been generated} when compiling \file{hello.pp}. This means that if
  1131. you used some units (the system unit, for instance) which were not compiled
  1132. with debugging support, no debugging support will be available for the code
  1133. in these units.
  1134. There are 2 solutions for this problem.
  1135. \begin{enumerate}
  1136. \item Recompile all units manually with the \var{-g} option.
  1137. \item Specify the 'build' option (\var{-B}) when compiling with debugging
  1138. support. This will recompile all units, and insert debugging information in
  1139. each of the units.
  1140. \end{enumerate}
  1141. The second option may have undesirable side effects. It may be that some
  1142. units aren't found, or compile incorrectly due to missing conditionals,
  1143. etc..
  1144. If all went well, the executable now contains the necessary information with
  1145. which you can debug it using \gnu \var{gdb}.
  1146. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1147. % Using gdb
  1148. \section{Using \var{gdb} to debug your program}
  1149. To use gdb to debug your program, you can start the debugger, and give it as
  1150. an option the {\em full} name of your program:
  1151. \begin{verbatim}
  1152. gdb hello
  1153. \end{verbatim}
  1154. Or, under \dos :
  1155. \begin{verbatim}
  1156. gdb hello.exe
  1157. \end{verbatim}
  1158. This starts the debugger, and the debugger immediately loads your program
  1159. into memory, but it does not run the program yet. Instead, you are presented
  1160. with the following (more or less) message, followed by the \var{gdb} prompt
  1161. \var{'(gdb)'}:
  1162. \begin{verbatim}
  1163. GDB is free software and you are welcome to distribute copies of it
  1164. under certain conditions; type "show copying" to see the conditions.
  1165. There is absolutely no warranty for GDB; type "show warranty" for details.
  1166. GDB 4.15.1 (i486-slackware-linux),
  1167. Copyright 1995 Free Software Foundation, Inc...
  1168. (gdb)
  1169. \end{verbatim}
  1170. To start the program you can use the \var{run} command. You can optionally
  1171. specify command-line parameters, which will then be fed to your program, for
  1172. example:
  1173. \begin{verbatim}
  1174. (gdb) run -option -anotheroption needed_argument
  1175. \end{verbatim}
  1176. If your program runs without problems, \var{gdb} will inform you of this,
  1177. and return the exit code of your program. If the exit code was zero, then
  1178. the message \var{'Program exited normally'}.
  1179. If something went wrong (a segmentation fault or so), \var{gdb} will stop
  1180. the execution of your program, and inform you of this with an appropriate
  1181. message. You can then use the other \var{gdb} commands to see what happened.
  1182. Alternatively, you can instruct \var{gdb} to stop at a certain point in your
  1183. program, with the \var{break} command.
  1184. Here is a short list of \var{gdb} commands, which you are likely to need when
  1185. debugging your program:
  1186. \begin{description}
  1187. \item [quit\ ] Exits the debugger.
  1188. \item [kill\ ] Stops a running program.
  1189. \item [help\ ] Gives help on all \var{gdb} commands.
  1190. \item [file\ ] Loads a new program into the debugger.
  1191. \item [directory\ ] Add a new directory to the search path for source
  1192. files.\\
  1193. {\em Remark:} My copy of gdb needs '.' to be added explicitly to the search
  1194. path, otherwise it doesn't find the sources.
  1195. \item [list\ ] Lists the program sources per 10 lines. As an option you can
  1196. specify a line number or function name.
  1197. \item [break\ ] Sets a breakpoint at a specified line or function
  1198. \item [awatch\ ] Sets a watch-point for an expression. A watch-point stops
  1199. execution of your program whenever the value of an expression is either
  1200. read or written.
  1201. \end{description}
  1202. for more information, see the \var{gdb} users' guide, or use the \var{'help'}
  1203. function in \var{gdb}.
  1204. The appendix {\ref{ch:GdbIniFile}} contains a sample init file for
  1205. \var{gdb}, which produces good results when debugging \fpc programs.
  1206. \section{Caveats when debugging with \var{gdb}}
  1207. There are some peculiarities of \fpc which you should be aware of when using
  1208. \var{gdb}. We list the main ones here:
  1209. \begin{enumerate}
  1210. \item \fpc generates information for GDB in uppercare letters. This is a
  1211. consequence of the fact that pascal is a case insensitive language. So, when
  1212. referring to a variable or function, you need to make it's name all
  1213. uppercase.
  1214. As an example, of you want to watch the value of a loop variable
  1215. \var{count}, you should type
  1216. \begin{verbatim}
  1217. watch COUNT
  1218. \end{verbatim}
  1219. Or if you want stop when a certain function (e.g \var{MyFunction}) is called,
  1220. type
  1221. \begin{verbatim}
  1222. break MYFUNCTION
  1223. \end{verbatim}
  1224. \item Line numbers may be off by a little. This is a bug in \fpc and will be
  1225. fixed as soon as possible.
  1226. \item \var{gdb} does not know sets.
  1227. \item \var{gdb} doesn't know strings. Strings are represented in \var{gdb}
  1228. as records with a length field and an array of char contaning the string.
  1229. You can also use the following user function to print strings:
  1230. \begin{verbatim}
  1231. define pst
  1232. set $pos=&$arg0
  1233. set $strlen = {byte}$pos
  1234. print {char}&$arg0.st@($strlen+1)
  1235. end
  1236. document pst
  1237. Print out a Pascal string
  1238. end
  1239. \end{verbatim}
  1240. If you insert it in your \file{gdb.ini} file, you can look at a string with this
  1241. function. There is a sample \file{gdb.ini} in appendix \ref{ch:GdbIniFile}.
  1242. \item Objects are difficult to handle, mainly because \var{gdb} is oriented
  1243. towards C and C++. The workaround implemented in \fpc is that object methods
  1244. are represented as functions, with an extra parameter \var{this} (all
  1245. lowercase !) The name of this function is a concatenation of the object type
  1246. and the function name, separated by two underscore characters.
  1247. For example, the method \var{TPoint.Draw} would be converted to
  1248. \var{TPOINT\_\_DRAW}, and could be stopped at with
  1249. \begin{verbatim}
  1250. break TPOINT__DRAW
  1251. \end{verbatim}
  1252. \item Global overloaded functions confuse \var{gdb} because they have the same
  1253. name. Thus you cannot set a breakpoint at an overloaded function, unless you
  1254. know it's line number, in which case you can set a breakpoint at the
  1255. starting linenumber of the function.
  1256. \end{enumerate}
  1257. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1258. % Using gprof
  1259. \section{Support for \var{gprof}, the \gnu profiler}
  1260. \label{se:gprof}
  1261. You can compile your programs with profiling support. for this, you just
  1262. have to use the compiler switch \var{-pg}. The compiler wil insert the
  1263. necessary stuff for profiling.
  1264. When you have done this, you can run your program uder the gnu profiler,
  1265. \var{gprof}, as follows :
  1266. \begin{verbatim}
  1267. gprog yourexe
  1268. \end{verbatim}
  1269. Where \file{yourexe} is the name of your executable.
  1270. You may want to capture the outpus of the profiler in a file, since it can
  1271. be quite a lot, as follows:
  1272. \begin{verbatim}
  1273. gprog yourexe >gprof.out
  1274. \end{verbatim}
  1275. For more information on the \gnu profiler \var{gprof}, see its manual.
  1276. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1277. % CGI.
  1278. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1279. \chapter{CGI programming in Free Pascal}
  1280. \label{ch:CGIProgramming}
  1281. In these days of heavy WWW traffic on the Internet, CGI scripts have become
  1282. an important topic in computer programming. While CGI programming can be
  1283. done with almost any tool you wish, most languages aren't designed for it.
  1284. Perl may be a notable exception, but perl is an interpreted language, the
  1285. executable is quite big, and hence puts a big load on the server machine.
  1286. Because of its simple, almost intuitive, string handling and its easy syntax,
  1287. Pascal is very well suited for CGI programming. Pascal allows you to quickly
  1288. produce some results, while giving you all the tools you need for more
  1289. complex programming. The basic RTL routines in principle are enough to get
  1290. the job done, but you can create, with relatively little effort, some units
  1291. which can be used as a base for more complex CGI programming.
  1292. That's why, in this chapter, we will discuss the basics of CGI in \fpc.
  1293. In the subsequent, we will assume that the server for which the programs are
  1294. created, are based upon the NCSA \var{httpd} WWW server, as the examples
  1295. will be based upon the NCSA method of CGI programming\footnote{... and it's
  1296. the only WWW-server I have to my disposition at the moment.}.
  1297. The two example programs in this chapter have been tested on the command line
  1298. and worked, under the condition that no spaces were present in the name and
  1299. value pairs provided to them.
  1300. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1301. % Getting your data
  1302. \section{Getting your data}
  1303. Your CGI program must react on data the user has filled in on the form which
  1304. your web-server gave him. The Web server takes the response on the form, and
  1305. feeds it to the CGI script.
  1306. There are essentially two ways of feeding the data to the CGI script. We will
  1307. discuss both.
  1308. %
  1309. %
  1310. % Data coming through standard input.
  1311. \subsection{Data coming through standard input.}
  1312. The first method of getting your data is through standard input. This method
  1313. is invoked when the form uses a form submission method of \var{POST}.
  1314. The web browser sets three environment variables \var{REQUEST\_METHOD},
  1315. \var{CONTENT\_TYPE} and \var{CONTENT\_LENGTH}. It feeds then the results of
  1316. the different fields through standard input to the CGI script.
  1317. All the Pascal program has to do is :
  1318. \begin{itemize}
  1319. \item Check the value of the \var{REQUEST\_METHOD} environment variable. The
  1320. \var{getenv} function will retrieve this value this for you.
  1321. \item Check the value of the \var{CONTENT\_TYPE} environment variable.
  1322. \item Read \var{CONTENT\_LENGTH} characters from standard input. \var{read
  1323. (c)} with \var{c} of type \var{char} will take care of that.
  1324. \end{itemize}
  1325. if you know that the request method will always be \var{POST}, and the
  1326. \var{CONTENT\_TYPE} will be correct, then you can skip the first two steps.
  1327. The third step can be done easier: read characters until you reach the
  1328. end-of-file marker of standard input.
  1329. The following example shows how this can be achieved:
  1330. \begin{verbatim}
  1331. program cgi_post;
  1332. uses dos;
  1333. const max_data = 1000;
  1334. type datarec = record
  1335. name,value : string;
  1336. end;
  1337. var data : array[1..max_data] of datarec;
  1338. i,nrdata : longint;
  1339. c : char;
  1340. literal,aname : boolean;
  1341. begin
  1342. writeln ('Content-type: text/html');
  1343. writeln;
  1344. if getenv('REQUEST_METHOD')<>'POST' then
  1345. begin
  1346. writeln ('This script should be referenced with a METHOD of POST');
  1347. write ('If you don''t understand this, see this ');
  1348. write ('< A HREF="http://www.ncsa.uiuc.edu/SDG/Softare/Mosaic');
  1349. writeln ('/Docs/fill-out-forms/overview.html">forms overview</A>.');
  1350. halt(1);
  1351. end;
  1352. if getenv('CONTENT_TYPE')<>'application/x-www-form-urlencoded' then
  1353. begin
  1354. writeln ('This script can only be used to decode form results');
  1355. halt(1)
  1356. end;
  1357. nrdata:=1;
  1358. aname:=true;
  1359. while not eof(input) do
  1360. begin
  1361. literal:=false;
  1362. read(c);
  1363. if c='\' then
  1364. begin
  1365. literal:=true;
  1366. read(c);
  1367. end;
  1368. if literal or ((c<>'=') and (c<>'&')) then
  1369. with data[nrdata] do
  1370. if aname then name:=name+c else value:=value+c
  1371. else
  1372. begin
  1373. if c='&' then
  1374. begin
  1375. inc (nrdata);
  1376. aname:=true;
  1377. end
  1378. else
  1379. aname:=false;
  1380. end
  1381. end;
  1382. writeln ('<H1>Form Results :</H1>');
  1383. writeln ('You submitted the following name/value pairs :');
  1384. writeln ('<UL>');
  1385. for i:=1 to nrdata do writeln ('<LI> ',data[i].name,' = ',data[i].value);
  1386. writeln ('</UL>');
  1387. end.
  1388. \end{verbatim}
  1389. While this program isn't shorter than the C program provided as an example
  1390. at NCSA, it doesn't need any other units. everythig is done using standard
  1391. Pascal procedures\footnote{actually, this program will give faulty results,
  1392. since spaces in the input are converted to plus signs by the web browser.
  1393. The program doesn't check for this, but that is easy to change.
  1394. The main concern here is to give the working principle.}.
  1395. Note that this program has a limitation: the length of names and values is
  1396. limited to 255 characters. This is due to the fact that strings in Pascal
  1397. have a maximal length of 255. It is of course easy to redefine the
  1398. \var{datarec} record in such a way that longer values are allowed.
  1399. In case you have to read the contents of a \var{TEXTAREA} form element,
  1400. this may be needed.
  1401. % Data passed through an environment variable
  1402. \subsection{Data passed through an environment variable}
  1403. If your form uses the \var{GET} method of passing it's data, the CGI script
  1404. needs to read the \var{QUERY\_STRING} environment variable to get it's data.
  1405. Since this variable can, and probably will, be more than 255 characters long,
  1406. you will not be able to use normal string methods, present in pascal. \fpc
  1407. implements the \var{pchar} type, which is a pointer to a null-terminated
  1408. array of characters.
  1409. And, fortunately, \fpc has a
  1410. \seestrings\ unit, which eases the use of the
  1411. \var{pchar} type.
  1412. The following example illustrates what to do in case of a method of \var{GET}
  1413. \begin{verbatim}
  1414. program cgi_get;
  1415. uses strings,linux;
  1416. const max_data = 1000;
  1417. type datarec = record
  1418. name,value : string;
  1419. end;
  1420. var data : array[1..max_data] of datarec;
  1421. i,nrdata : longint;
  1422. p : PChar;
  1423. literal,aname : boolean;
  1424. begin
  1425. Writeln ('Content-type: text/html');
  1426. Writeln;
  1427. if StrComp(GetEnv('REQUEST_METHOD'),'POST')<>0 then
  1428. begin
  1429. Writeln ('This script should be referenced with a METHOD of GET');
  1430. write ('If you don''t understand this, see this ');
  1431. write ('< A HREF="http://www.ncsa.uiuc.edu/SDG/Softare/Mosaic');
  1432. Writeln ('/Docs/fill-out-forms/overview.html">forms overview</A>.');
  1433. halt(1);
  1434. end;
  1435. p:=GetEnv('QUERY_STRING');
  1436. nrdata:=1;
  1437. aname:=true;
  1438. while p^<>#0 do
  1439. begin
  1440. literal:=false;
  1441. if p^='\' then
  1442. begin
  1443. literal:=true;
  1444. inc(longint(p));
  1445. end;
  1446. if ((p^<>'=') and (p^<>'&')) or literal then
  1447. with data[nrdata] do
  1448. if aname then name:=name+p^ else value:=value+p^
  1449. else
  1450. begin
  1451. if p^='&' then
  1452. begin
  1453. inc (nrdata);
  1454. aname:=true;
  1455. end
  1456. else
  1457. aname:=false;
  1458. end;
  1459. inc(longint(p));
  1460. end;
  1461. Writeln ('<H1>Form Results :</H1>');
  1462. Writeln ('You submitted the following name/value pairs :');
  1463. Writeln ('<UL>');
  1464. for i:=1 to nrdata do writeln ('<LI> ',data[i].name,' = ',data[i].value);
  1465. Writeln ('</UL>');
  1466. end.
  1467. \end{verbatim}
  1468. Although it may not be written in the most elegant way, this program does
  1469. the same thing as the previous one. It also suffers from the same drawback,
  1470. namely the limited length of the \var{value} field of the \var{datarec}.
  1471. This drawback can be remedied by redefining \var{datarec} as follows:
  1472. \begin{verbatim}
  1473. type datarec = record;
  1474. name,value : pchar;
  1475. end;
  1476. \end{verbatim}
  1477. and assigning at run time enough space to keep the contents of the value
  1478. field. This can be done with a
  1479. \begin{verbatim}
  1480. getmem (data[nrdata].value,needed_number_of_bytes);
  1481. \end{verbatim}
  1482. call. After that you can do a
  1483. \begin{verbatim}
  1484. strlcopy (data[nrdata].value,p,needed_number_of_bytes);
  1485. \end{verbatim}
  1486. to copy the data into place.
  1487. You may have noticed the following unorthodox call :
  1488. \begin{verbatim}
  1489. inc(longint(p));
  1490. \end{verbatim}
  1491. \fpc doesn't give you pointer arithmetic as in C. However, \var{longints} and
  1492. \var{pointers} have the same length (namely 4 bytes). Doing a type-cast to a
  1493. \var{longint} allows you to do arithmetic on the \var{pointer}.
  1494. Note however, that this is a non-portable call. This may work on the I386
  1495. processor, but not on a ALPHA processor (where a pointer is 8 bytes long).
  1496. This will be remedied in future releases of \fpc.
  1497. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1498. % Producing output
  1499. \section{Producing output}
  1500. The previous section concentrated mostly on getting input from the web
  1501. server. To send the reply to the server, you don't need to do anything
  1502. special.You just print your data on standard output, and the Web-server will
  1503. intercept this, and send your output to the WWW-client waiting for it.
  1504. You can print anything you want, the only thing you must take care of is
  1505. that you supply a \var{Contents-type} line, followed by an empty line, as
  1506. follows:
  1507. \begin{verbatim}
  1508. Writeln ('Content-type: text/html');
  1509. Writeln;
  1510. { ...start output of the form... }
  1511. \end{verbatim}
  1512. And that's all there is to it !
  1513. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1514. % I'm under Windows, what now ?
  1515. \section{I'm under Windows, what now ?}
  1516. Under Windows the system of writing CGI scripts is totally different. If you
  1517. use \fpc under Windows then you also should be able to do CGI programming,
  1518. but the above instructions will not work.
  1519. If some kind soul is willing to write a section on CGI programming under
  1520. Windows, I'd be willing to include it here.
  1521. \appendix
  1522. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1523. % APPENDIX A.
  1524. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1525. \chapter{Alphabetical listing of command-line options}
  1526. The following is alphabetical listing of all command-line options, as
  1527. generated by the compiler:
  1528. \begin{verbatim}
  1529. ppc386 [options] <inputfile> [options]
  1530. + switch option on, - off
  1531. -a the compiler doesn't delete the generated assembler file
  1532. -B+ build
  1533. -C code generation options
  1534. -Ca not implemented
  1535. -Ce not implemented
  1536. -CD Dynamic linking
  1537. -Ch<n> <n> bytes heap (between 1023 and 67107840)
  1538. -Ci IO-checking
  1539. -Cn omit linking stage
  1540. -Co check overflow of integer operations
  1541. -Cr range checking
  1542. -Ct stack checking
  1543. -CS static linking
  1544. -d<x> defines the symbol <x>
  1545. -e<x> set path to executables
  1546. -E same as -Cn
  1547. -g generate debugger information
  1548. -gp generate also profile code for gprof
  1549. -F set file names and paths
  1550. -Fe<x> redirect error output to <x>
  1551. -Fg<x> <x> search path for the GNU C lib
  1552. -Fr<x> <x> search path for the error message file
  1553. -Fi<x> adds <x> to include path
  1554. -Fl<x> adds <x> to library path
  1555. -Fu<x> adds <x> to unit path
  1556. -k<x> Pass <x> to the linker
  1557. -L set language
  1558. -LD german
  1559. -LE english
  1560. -l write logo
  1561. -i information
  1562. -n don't read the default config file
  1563. -o<x> change the name of the executable produced to <x>
  1564. -pg generate profile code for gprof
  1565. -P use pipes instead of creating temporary assembler files
  1566. -S syntax options
  1567. -S2 switch some Delphi 2 extension on
  1568. -Sc supports operators like C (*=,+=,/= and -=)
  1569. -Se compiler stops after the first error
  1570. -Sg allows LABEL and GOTO
  1571. -Si support C++ stlyed INLINE
  1572. -Sm support macros like C (global)
  1573. -So tries to be TP/BP 7.0 compatible
  1574. -Ss constructor name must be init (destructor must be done)
  1575. -St allows static keyword in objects
  1576. -s don't call assembler and linker (only with -a)
  1577. -T<x> Target operating system
  1578. -TGO32V1 DOS extender by DJ Delorie
  1579. -TOS2 OS/2 2.x
  1580. -TLINUX Linux
  1581. -TWin32 Windows 32 Bit
  1582. -TGO32V2 version 2 of DJ Delorie DOS extender
  1583. -u<x> undefines the symbol <x>
  1584. -U unit options
  1585. -Uls make static library from unit
  1586. -Uld make dynamic library from unit
  1587. -Un don't check the unit name
  1588. -Up<x> same as -Fu<x>
  1589. -Us compile a system unit
  1590. -v<x> Be verbose. <x> is a combination of the following letters :
  1591. e : Show errors (default) d : Show debug info
  1592. w : Show warnings u : Show used files
  1593. n : Show notes t : Show tried files
  1594. h : Show hints m : Show defined macros
  1595. i : Show general info p : Show compiled procedures
  1596. l : Show linenumbers c : Show conditionals
  1597. a : Show everything 0 : Show nothing (except errors)
  1598. -X executable options
  1599. -Xc link with the c library
  1600. -Xs strip all symbols from executable
  1601. Processor specific options:
  1602. -A output format
  1603. -Aatt AT&T assembler
  1604. -Ao coff file using GNU AS
  1605. -Aobj OMF file using NASM
  1606. -Anasm coff file using NASM
  1607. -Amasm assembler for the Microsoft/Borland/Watcom assembler
  1608. -R assembler reading style
  1609. -Ratt read AT&T style assembler
  1610. -Rintel read Intel style assembler
  1611. -Rdirect copy assembler text directly to assembler file
  1612. -O optimizations
  1613. -Oa simple optimizations
  1614. -Og optimize for size
  1615. -OG optimize for time
  1616. -Ox optimize maximum
  1617. -Oz uncertain optimizes (see docs)
  1618. -O2 optimize for Pentium II (tm)
  1619. -O3 optimize for i386
  1620. -O4 optimize for i486
  1621. -O5 optimize for Pentium (tm)
  1622. -O6 optimizations for PentiumPro (tm)
  1623. -? shows this help
  1624. -h shows this help without waiting
  1625. \end{verbatim}
  1626. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1627. % APPENDIX B.
  1628. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1629. \chapter{Alphabetical list of reserved words}
  1630. \label{ch:reserved}
  1631. \latex{\begin{multicols}{3}}% \texttt
  1632. \begin{verbatim}
  1633. absolute
  1634. abstract
  1635. and
  1636. array
  1637. as
  1638. asm
  1639. assembler
  1640. begin
  1641. break
  1642. case
  1643. cdecl
  1644. class
  1645. const
  1646. constructor
  1647. continue
  1648. destructor
  1649. dispose
  1650. div
  1651. do
  1652. downto
  1653. else
  1654. end
  1655. except
  1656. exit
  1657. export
  1658. exports
  1659. external
  1660. fail
  1661. false
  1662. far
  1663. file
  1664. finally
  1665. for
  1666. forward
  1667. function
  1668. goto
  1669. if
  1670. implementation
  1671. in
  1672. index
  1673. inherited
  1674. initialization
  1675. inline
  1676. interface
  1677. interrupt
  1678. is
  1679. label
  1680. library
  1681. mod
  1682. name
  1683. near
  1684. new
  1685. nil
  1686. not
  1687. object
  1688. of
  1689. on
  1690. operator
  1691. or
  1692. otherwise
  1693. packed
  1694. private
  1695. procedure
  1696. program
  1697. property
  1698. protected
  1699. public
  1700. raise
  1701. record
  1702. repeat
  1703. self
  1704. set
  1705. shl
  1706. shr
  1707. stdcall
  1708. string
  1709. then
  1710. to
  1711. true
  1712. try
  1713. type
  1714. unit
  1715. until
  1716. uses
  1717. var
  1718. virtual
  1719. while
  1720. with
  1721. xor
  1722. \end{verbatim}
  1723. \latex{\end{multicols}}
  1724. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1725. % APPENDIX C.
  1726. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1727. \chapter{Compiler error messages}
  1728. \label{ch:ErrorMessages}
  1729. This appendix is meant to list all the compiler errors. the list of compiler
  1730. errors is fairly complete, the assembler errors are less complete.
  1731. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1732. % Compiler errors.
  1733. \section{Compiler errors}
  1734. The following is a list of general compiler errors.
  1735. \begin{description}
  1736. \item [unexpected end of file]
  1737. this typically happens in on of the following cases :
  1738. \begin{itemize}
  1739. \item The source file ends befor then final \var{end.} statement. This
  1740. happens mostly when the \var{begin} and \var{end} statements aren't
  1741. balanced;
  1742. \item An include file ends in the middle of a statement.
  1743. \item A comment wasn't closed.
  1744. \end{itemize}
  1745. \item [duplicate identifier:]
  1746. The identifier was already declared in the current scope.
  1747. \item [syntax error:]
  1748. An error against the Turbo Pascal language was encountered. This happens
  1749. typically when an illegal character is found in the sources file.
  1750. \item [Parser - syntax error]
  1751. An error against the Turbo Pascal language was encountered. This happens
  1752. typically when an illegal character is found in the sources file.
  1753. \item [out of memory]
  1754. The compiler doesn't have enough memory to compile your program. There are
  1755. several remedies for this:
  1756. \begin{itemize}
  1757. \item If you're using the build option of the compiler, try compiling the
  1758. different units manually.
  1759. \item If you're compiling a huge program, split it up in units, and compile
  1760. these separately.
  1761. \item If the previous two don't work, recompile the compiler with a bigger
  1762. heap (you can use the \var{-Ch} option for this, \seeo{Ch})
  1763. \end{itemize}
  1764. \item [unknown identifier]
  1765. The identifier encountered hasn't been declared, or is used outside the
  1766. scope where it's defined.
  1767. \item [illegal character]
  1768. An illegal character was encountered in the input file.
  1769. \item [source too long]
  1770. The compiler cannot cope with source files longer than (???)
  1771. \item [procedure type INLINE not supported]
  1772. You tried to compile a program with C++ style inlining, and forgot to
  1773. specify the \var{-Si} option (\seeo{Si}). The compiler doesn't support C++
  1774. styled inlining by default.
  1775. \item [procedure type NEAR ignored]
  1776. This is a warning. \var{NEAR} is a construct for 8 or 16 bit programs. Since
  1777. the compile generates 32 bit programs, it ignores this directive.
  1778. \item [procedure type FAR ignored]
  1779. This is a warning. \var{FAR} is a construct for 8 or 16 bit programs. Since
  1780. the compile generates 32 bit programs, it ignores this directive.
  1781. \item [INTERRUPT ignored]
  1782. Interrupt procedures aren't possible on operating systems, other than DOS,
  1783. it isn't allowed to take over an interrupt at the user level. (versions
  1784. older than 0.9.2 didn't have \var{INTERRUPT} support.
  1785. \item [private methods shouldn't be VIRTUAL]
  1786. You declared a method in the private part of a object (class) as
  1787. \var{virtual}. This is not allowed. Private methods cannot be overridden
  1788. anyway.
  1789. \item [constructor can't be private or protected]
  1790. Constructors must be in the 'public' part of an object (class) declaration.
  1791. \item [destructor can't be private or protected]
  1792. Destructors must be in the 'public' part of an object (class) declaration.
  1793. \item [identifier not found]
  1794. \item [local class definitions are not allowed]
  1795. Classes must be defined globally.
  1796. \item [anonym class definitions are not allowed]
  1797. \item [type identifier expected]
  1798. The identifier is not a type, or you forgot to supply a type identifier.
  1799. \item [identifier already as type identifier declared]
  1800. You are trying to redefine a type.
  1801. \item [type identifier not defined]
  1802. The compiler encountered an unknown type.
  1803. \item [type mismatch]
  1804. This can happen in many cases:
  1805. \begin{itemize}
  1806. \item The variable you're assigning to is of a different type than the
  1807. expression in the assignment.
  1808. \item You are calling a function or procedure with parameters that are
  1809. incompatible with the parameters in the function or procedure definition.
  1810. \end{itemize}
  1811. \item [statement expected]
  1812. \item [illegal integer constant]
  1813. You made an exression which isn't an integer, and the compiler expects the
  1814. result to be an integer.
  1815. \item [illegal expression]
  1816. \item [expression too complicated - FPU stack overflow]
  1817. Your expression is too long for the compiler. You should try dividing the
  1818. construct over multiple assignments.
  1819. \item [CONTINUE not allowed]
  1820. You're trying to use \var{continue} outside a loop construction.
  1821. \item [BREAK not allowed]
  1822. You're trying to use \var{break} outside a loop construction.
  1823. \item [illegal qualifier]
  1824. One of the following is appending :
  1825. \begin{itemize}
  1826. \item You're trying to access a field of a variable that is not a record.
  1827. \item You're indexing a variable that is not an array.
  1828. \item You're dereferencing a variable that is not a pointer.
  1829. \end{itemize}
  1830. \item [illegal counter variable]
  1831. The type of a \var{for} loop must be ordinal.
  1832. \item [ordinal value expected]
  1833. The expression must be of ordinal type (i.e. maximum a Longint)
  1834. \item [high range limit < low range limit]
  1835. You are declaring a subrange, and the lower limit is higher than the high
  1836. limit of the range.
  1837. \item [illegal unit name]
  1838. The name of the unit doesn't match the file name.
  1839. \item [unknown format of unit file]
  1840. The unit the compiler is trying to read is corrupted, or generated with a
  1841. newer version of the compiler.
  1842. \item [Reading PPU-File]
  1843. The unit the compiler is trying to read is corrupted, or generated with a
  1844. newer version of the compiler.
  1845. \item [Invalid PPU-File entry]
  1846. The unit the compiler is trying to read is corrupted, or generated with a
  1847. newer version of the compiler.
  1848. \item [circular unit use]
  1849. Two units are using each other in the interface part. This is only allowed
  1850. in the implementation part.
  1851. \item [too many units]
  1852. \fpc has a limit of 1024 units in a program. You can change this behavior
  1853. by changing the \var{maxunits} constant in the \file{files.pas} file of the
  1854. compiler, and recompiling the compiler.
  1855. \item [illegal char constant]
  1856. The compiler expects a character constant, but finds something else.
  1857. \item [overloaded identifier isn't a function identifier]
  1858. The compiler encountered a symbol with the same name a s an overloaded
  1859. function, but it isn't a function it can overload.
  1860. \item [overloaded functions have the same parameter list]
  1861. You're declaring overloaded functions, but with the same parameter list.
  1862. Overloaded function must have at least 1 different parameter in their
  1863. declaration.
  1864. \item [illegal parameter list]
  1865. You are calling a function with parameters that are of a different type than
  1866. the declared parameters of the function.
  1867. \item [can't determine which overloaded function to call]
  1868. You're calling overloaded functions with a parameter that doesn't correspond
  1869. to any of the declared function parameter lists. e.g. when you have declared
  1870. a function with parameters \var{word} and \var{longint}, and then you call
  1871. it with a parameter which is of type \var{integer}.
  1872. \item [forward declaration not solved:]
  1873. This can happen in two cases:
  1874. \begin{itemize}
  1875. \item This happens when you declare a function (in the \var{interface} part, or
  1876. with a \var{forward} directive, but do not implement it.
  1877. \item You reference a type which isn't declared in the current \var{type}
  1878. block.
  1879. \end{itemize}
  1880. \item [input file not found]
  1881. \fpc cannot find the program or unit source file, or the included file isn't
  1882. found.
  1883. \item [function header doesn't match the forward declaration]
  1884. You declared the function in the \var{interface} part, or with the
  1885. \var{forward} directive, but define it with a different parameter list.
  1886. \item [unknown field identifier]
  1887. The field doesn't exist in the record definition.
  1888. \item [parameter list size exceeds 65535 bytes]
  1889. The I386 processor limits the parameter list to 65535 bytes (the \var{RET}
  1890. instruction causes this)
  1891. \item [function nesting > 31]
  1892. You can nest function definitions only 31 times.
  1893. \item [illegal compiler switch]
  1894. You included a compiler switch (i.e. \var{\{\$... \}}) which the compiler
  1895. doesn't know.
  1896. \item [can't open include file]
  1897. You want to include (i.e \var{\{\$i file\}}) which the compiler doesn't
  1898. find. Check if the filename is correct.
  1899. \item [record or class type expected]
  1900. The variable or expression isn't of the type \var{record} or \var{class}.
  1901. \item [only values can be jumped over in enumeration types]
  1902. \fpc allows enumeration constructions as in C. Given the following
  1903. declaration two declarations:
  1904. \begin{verbatim}
  1905. type a = (A_A,A_B,A_E=:6,A_UAS:=200);
  1906. type a = (A_A,A_B,A_E=:6,A_UAS:=4);
  1907. \end{verbatim}
  1908. The second declaration would produce an error. \var{A\_UAS} needs to have a
  1909. value higher than \var{A\_E}, i.e. at least 7.
  1910. \item [pointer type expected]
  1911. The variable or expression isn't of the type \var{pointer}.
  1912. \item [unit is compiled for another operating system]
  1913. The unit was compiled with a different target than the target for which
  1914. you're compiling now. (see the option \var{-T} \seeo{T}).
  1915. \item [typed constants of classes are not allowed]
  1916. You cannot declare a constant of type class or object.
  1917. \item [duplicate case label]
  1918. You are specifying the same label 2 times in a \var{case} statement.
  1919. \item [range check error while evaluating constants]
  1920. The constants are out of their allowed range.
  1921. \item [illegal type conversion]
  1922. When doing a type-cast, you must take care that the sizes of the variable and
  1923. the destination type are the same.
  1924. \item [class type expected]
  1925. The variable of expression isn't of the type \var{class}.
  1926. \item [functions variables of overloaded functions are not allowed]
  1927. You are trying to assign an overloaded function to a procedural variable.
  1928. This isn't allowed.
  1929. \item [can't create assembler file]
  1930. The assembler output file cannot be opened. This can have many causes, but
  1931. 'disk full' is a reasonable guess.
  1932. \item [string length must be a value from 1 to 255]
  1933. The length of a string in Pascal is limited to 255 characters. You are
  1934. trying to declare a string with length greater than 255.
  1935. \item [class identifier expected]
  1936. The variable isn't of type \var{class}.
  1937. \item [method identifier expected]
  1938. This identifier is not a method.
  1939. \item [function header doesn't match any method of this class]
  1940. You are defining a function as a class method, but no such function was
  1941. declared in the class.
  1942. \item [use extended syntax of DISPOSE and NEW to generate instances of classes]
  1943. If you have a pointer \var{a} to a class type, then the statement
  1944. \var{new(a)} will not initialize the class (i.e. the constructor isn't
  1945. called), although space will be allocated. you should issue the
  1946. \var{new(a,init)} statement. This will allocate space, and call the
  1947. constructor of the class.
  1948. \item [file types must be var parameters]
  1949. You cannot specify files as value parameters, i.e. they must always be
  1950. declared \var{var} parameters.
  1951. \item [string exceeds line]
  1952. You forgot probably to include the closing ' in a string, so it occupies
  1953. multiple lines.
  1954. \item [illegal version of the unit:]
  1955. This unit was compiled with an earlier version of \fpc.
  1956. \item [illegal floating point constant]
  1957. \item [destructors can't have parameters]
  1958. You are declaring a destructor with a parameter list. Destructor methods
  1959. cannot have parameters.
  1960. \item [FAIL can be used in constructors only]
  1961. You are using the \var{FAIl} instruction outside a constructor method.
  1962. \item [records fields can be aligned to 1,2 or 4 bytes only]
  1963. You are specifying the \var{\{\$PACKRECORDS n\} } with an illegal value for
  1964. \var{n}. Only 1,2 or 4 are valid in this case.
  1965. \item [too many \$ENDIFs or \$ELSEs]
  1966. Your \var{\{\$IFDEF ..\}} and {\{\$ENDIF\}} statements aren't balanced.
  1967. \item [\$ENDIF expected]
  1968. Your \var{\{\$IFDEF ..\}} and {\{\$ENDIF\}} statements aren't balanced.
  1969. \item [illegal call by reference parameters]
  1970. \item [can't generate DEF file]
  1971. \ostwo only. The DEF file cannot be generated.
  1972. \item [all overloaded methods must be virtual if one is virtual:]
  1973. If you declare overloaded methods in a class, then they should either all be
  1974. virtual, or none. You cannot mix them.
  1975. \item [overloaded methods which are virtual must have the same return type:]
  1976. If you declare virtual overloaded methods in a class definition, they must
  1977. have the same return type.
  1978. \item [all overloaded virtual methods must support exceptions if one support exceptions:]
  1979. If you declare overloaded virtual methods in a class, then they should either
  1980. all support exceptions, or none. You cannot mix them.
  1981. \item [EXPORT declared functions can't be called]
  1982. You are trying to call a procedure you declared as \var{export}. Due to the
  1983. different calling scheme of \fpc and C, you cannot call such a function from
  1984. within your Pascal program.
  1985. \item [EXPORT declared functions can't be nested]
  1986. You cannot declare a function or procedure within a function or procedure
  1987. that was declared as an export procedure.
  1988. \item [methods can't be EXPORTed]
  1989. You cannot declare a procedure that is a method for an object as
  1990. \var{export}ed. That is, you methods cannot be called from a C program.
  1991. \item [SELF is only allowed in methods]
  1992. You are trying to use the \var{self} parameter outside an object's method.
  1993. Only methods get passed the \var{self} parameters.
  1994. \item [call by var parameters have to match exactly]
  1995. When calling a function declared with \var{var} parameters, the variables in
  1996. the function call must be of exactly the same type. There is no automatic
  1997. type conversion.
  1998. \item [class identifier expected]
  1999. The variable isn't of type \var{class}.
  2000. \item [class isn't a super class of the current class]
  2001. When calling inherited methods, you are trying to call a method of a strange
  2002. class. You can only call an inherited method of a parent class.
  2003. \item [methods can be only in other methods called direct with type identifier of the class]
  2004. A construction like \var{sometype.somemethod} is only allowed in a method.
  2005. \item [illegal type: pointer to class expected]
  2006. You specified an illegal type.
  2007. \item [possible illegal call of constructor or destructor (doesn't match to this context)]
  2008. \item [class should have one destructor only]
  2009. You can declare only one destructor for a class.
  2010. \item [expression must be constructor call]
  2011. When using the extended syntax of \var{new}, you must specify the constructor
  2012. method of the class you are trying to create. The procedure you specified
  2013. is not a constructor.
  2014. \item [identifier idents no member]
  2015. When using the extended syntax of \var{new}, you must specify the constructor
  2016. method of the class you are trying to create. The procedure you specified
  2017. does not exist.
  2018. \item [expression must be destructor call]
  2019. When using the extended syntax of \var{dispose}, you must specify the
  2020. destructor method of the class you are trying to dispose of.
  2021. The procedure you specified is not a destructor.
  2022. \item [type conflict between set elements]
  2023. There is at least one set element which is of the wrong type, i.e. not of
  2024. the set type.
  2025. \item [illegal expression in set constructor]
  2026. \item [type conflict between set elements]
  2027. You are specifying elements of a different type for a set.
  2028. \item [illegal use of ':']
  2029. \item [expression type must be class or record type]
  2030. The expression isn't of type class or record.
  2031. \item [the operator / isn't defined for integer, the result will be real, use DIV instead]
  2032. When using the '/' operator in \fpc the result will be of type real, when
  2033. used with integers.
  2034. \item [can't write PPU file]
  2035. There is a problem when writing to the unit file.
  2036. \item [illegal order of record elements]
  2037. When declaring a constant record, you specified the fields in the wrong
  2038. order.
  2039. \item [the name of constructors must be INIT]
  2040. You are declaring a constructor with a name which isn't \var{init}, and the
  2041. \var{-Ss} switch is in effect. See the \var{-Ss} switch (\seeo{Ss}).
  2042. \item [the name of constructors must be DONE]
  2043. You are declaring a constructor with a name which isn't \var{done}, and the
  2044. \var{-Ss} switch is in effect. See the \var{-Ss} switch (\seeo{Ss}).
  2045. \item [set element type mismatch]
  2046. The type of the element doesn't equal the set type.
  2047. \item [illegal label declaration]
  2048. \item [label not found]
  2049. A \var{goto label} was encountered, but the label isn't declared.
  2050. \item [GOTO and LABEL are not supported (use command line switch -Sg)]
  2051. You must compile a program which has \var{label}s and \var{goto} statements
  2052. with the \var{-Sg} switch. By default, \var{label} and \var{goto} aren't
  2053. supported.
  2054. \item [set expected]
  2055. The variable or expression isn't of type \var{set}.
  2056. \item [identifier isn't a label]
  2057. The identifier specified after the \var{goto} isn't of type label.
  2058. \item [label already defined]
  2059. You're attempting to define a label two times. (i.e. you put the same label
  2060. on two different places.)
  2061. \item [label isn't defined:]
  2062. A label was declared, but not defined.
  2063. \item [constructors and destructors must be methods]
  2064. You're declaring a procedure as destructor or constructor, when the
  2065. procedure isn't a class method.
  2066. \item [error when assembling]
  2067. An error occurred when assembling. This can have many causes.
  2068. \item [identifier not used:]
  2069. This is a warning. The identifier was declared (locally or globally) but
  2070. wasn't used (locally or globally).
  2071. \item [functions with void return value can't return any value]
  2072. In \fpc, you can specify a return value for a function when using
  2073. the \var{exit} statement. This error occurs when you try to do this with a
  2074. procedure. Procedures cannot return a value.
  2075. \item [Hmmm..., this code can't be much efficient]
  2076. You construction seems dubious to the compiler.
  2077. \item [unreachable code]
  2078. You specified a loop which will never be executed. Example:
  2079. \begin{verbatim}
  2080. while false do
  2081. begin
  2082. {.. code ...}
  2083. end;
  2084. \end{verbatim}
  2085. \item [This overloaded function can't be local (must be exported)]
  2086. You are defining a overloaded function in the implementation part of a unit,
  2087. but there is no corresponding declaration in the interface part of the unit.
  2088. \item [It's not possible to overload this operator]
  2089. You are trying to overload an operator which cannot be overloaded.
  2090. \item [Abstract methods can't be called direct]
  2091. \fpc understands the \var{abstract} keyword.
  2092. \item [the mix of CLASSES and OBJECTS are not allowed]
  2093. You cannot use \var{object} and \var{class} intertwined.
  2094. \item [macro buffer overflow while reading or expanding a macro]
  2095. Your macro or it's result was too long for the compiler.
  2096. \item [keyword redefined as macro has no effect]
  2097. You cannot redefine keywords with macros.
  2098. \item [extension of macros exceeds a deep of 16,\\ perhaps there is a recursive macro definition (crashes the compiler)]
  2099. When expanding a macro macros have been nested to a level of 16.
  2100. \item [ENDIF without IF(N)DEF]
  2101. Your code contains more \var{\{\$ENDIF\}} than \var{\{\$IF(N)DEF\}}
  2102. statements.
  2103. \item [user defined:]
  2104. A user defined warning occurred. see also the \progref
  2105. \item [linker: Duplicate symbol:]
  2106. Two global symbols in the code have the same name.
  2107. \item [linker: Error while reading object file]
  2108. The linker couldn't read the object file (the assembled file).
  2109. \item [linker: object file not found]
  2110. The linker didn't find the object file (the assembled file).
  2111. \item [linker: illegal magic number in file:]
  2112. The linker cannot determine the type of a file it wants to link in. The type
  2113. of a link file is specified using a magic number, which is some pre-defined
  2114. constant, unique for each system.
  2115. \item [The extended syntax of new or dispose isn't allowed for a class]
  2116. You cannot generate an instance of a class with the extended syntax of
  2117. \var{new}. The constructor must be used for that. For the same reason, you
  2118. cannot call \var{Dispose} to de-allocate an instance of a class, the
  2119. destructor must be used for that.
  2120. \item [To generate an instance of a class or an object with an abstract method isn't allowed]
  2121. You are trying to generate an instance of a class which has an abstract
  2122. method that wasn't overridden.
  2123. \item [Only virtual methods can be abstract]
  2124. You are declaring a method as abstract, when it isn't declared to be
  2125. virtual.
  2126. \item [Abstract methods shouldn't have any definition (with function body)]
  2127. Abstract methods can only be declared, you cannot implement them. They
  2128. should be overridden by a descendant class.
  2129. \item [can't call the assembler]
  2130. An error occurred when calling the assembler.
  2131. \item [can't call o2obj]
  2132. An error occurred when calling the \var{o} to \var{obj} conversion program.
  2133. \item [asm syntax error]
  2134. There is an error in the assembly language.
  2135. \item [register name expected]
  2136. There is an error in the assembly language. The assembler expected a
  2137. register and got something else.
  2138. \item [asm size mismatch]
  2139. There is an error in the assembly language. The sizes of operands and
  2140. registers don't match.
  2141. \item [no instr match,]
  2142. There is an error in the assembly language. An unknown instruction was
  2143. encountered.
  2144. \item [can't compile unit:]
  2145. When trying to do a build, the compiler cannot compile one of the units.
  2146. \item [Re-raise isn't possible there]
  2147. You are trying to raise an exception where it isn't allowed. You can only
  2148. raise exceptions in an \var{except} block.
  2149. \item [ Syntax error while parsing a conditional compiling expression ]
  2150. \item [ Evaluating a conditional compiling expression ]
  2151. There is an error in the expression following the \var{\{\$if \}} compiler
  2152. directive.
  2153. \item [ Keyword redefined as macro has no effect ]
  2154. You cannot redefine Pascal keywords with macros. If you, for instance would
  2155. want to redefine the exit command you'd get this error.
  2156. \item [ compiler switches aren't allowed in (* ... *) styled comments ]
  2157. Compiler switches should always be between \var{\{ \}} comment delimiters.
  2158. \item [ No DLL File specified ]
  2159. \item [ Illegal open parameter ]
  2160. You are trying to use the wrong type for an open parameter.
  2161. \item [ Illegal floating point constant ]
  2162. The compiler expects a floating point expression, and gets something else.
  2163. \item [ string types doesn't match, because of \$V+ mode ]
  2164. When compiling in \var{\{\$V+ \}} mode, the string you pass as a parameter
  2165. should be of the exact same type as the declared parameter of the procedure.
  2166. \item [ Only class methods can be referred with class references ]
  2167. This error occurs in a situation like the following:
  2168. \begin{verbatim}
  2169. Type :
  2170. Tclass = Class of Tobject;
  2171. Var C : TClass;
  2172. begin
  2173. ...
  2174. C.free
  2175. \end{verbatim}
  2176. \var{Free} is not a class method and hence cannot be called with a class
  2177. reference.
  2178. \item [ Only class methods can be accessed in class methods ]
  2179. This is related to the previous error. You cannot call a method of an object
  2180. from a inside a class method. The following code would produce this error:
  2181. \begin{verbatim}
  2182. class procedure tobject.x;
  2183. begin
  2184. free
  2185. \end{verbatim}
  2186. Because free is a normal method of a class it cannot be called from a class
  2187. method.
  2188. \item [ Constant and CASE types do not match ]
  2189. One of the labels is not of the same type as the case variable.
  2190. \item [ The symbol can't be exported from a library ]
  2191. You can only export procedures and functions when you write a library. You
  2192. cannot export variables or constants.
  2193. \item [ A virtual method must be overridden using the OVERRIDE directive: ]
  2194. A method that is declared \var{virtual} in a parent class, should be
  2195. overridden in the descendent class with the \var{override} directive. If you
  2196. don't specify the \var{override} directive, you will hide the parent method;
  2197. you will not override it.
  2198. \item [ There is no method in an ancestor class to be overridden: ]
  2199. You try to \var{override} a virtual method of a parent class that doesn't
  2200. exist.
  2201. \item [ No member is provided to access property ]
  2202. You specified no \var{read} directive for a property.
  2203. \item [ Illegal symbol for property access ]
  2204. There is an error in the \var{read} or \var{write} directives for an array
  2205. property. When you declare an array property, you can only access it with
  2206. procedures and functions. The following code woud cause such an error.
  2207. \begin{verbatim}
  2208. tmyobject = class
  2209. i : integer;
  2210. property x [i : integer]: integer read I write i;
  2211. \end{verbatim}
  2212. \item [ Cannot write a protected field of an object ]
  2213. Fields that are declared in a \var{protected} section of an object or class
  2214. declaration cannot be accessed outside that objects methods.
  2215. \item [ range check error in set constructor or duplicate set element ]
  2216. The declaration of a set contains an error. Either one of the elements is
  2217. outside the range of the set type, either two of the elements are in fact
  2218. the same.
  2219. \item [ Pointer to class expected ]
  2220. The compiler expects a reference to a class.
  2221. \item [ Operator is not overloaded ]
  2222. You're trying to use an overloaded operator when it isn't overloaded for
  2223. this type.
  2224. \item [ Variable or type indentifier expected ]
  2225. \item [ Assembler incompatible with function return value ]
  2226. You're trying to implement a \var{assembler} function, but the return type
  2227. of the function doesn't allow that.
  2228. \item [ Procedure overloading is switched off ]
  2229. You're trying to compile overloaded procedures with the \var{-So} (Turbo Pascal
  2230. compatibility) switch. Remove the switch.
  2231. \item [ Comparative operator must return a boolean value ]
  2232. When overloading the \var{=} operator, the function must return a boolean
  2233. value.
  2234. \item [ Use of unsupported feature! ]
  2235. You're trying to force the compiler into doing something it cannot do yet.
  2236. \item [ absolute can only be associated to ONE variable ]
  2237. You cannot specify more than one variable before the \var{absolute} directive.
  2238. Thus, the following construct will provide this error:
  2239. \begin{verbatim}
  2240. Var Z : Longint;
  2241. X,Y : Longint absolute Z;
  2242. \end{verbatim}
  2243. \item [ absolute can only be associated a var or const ]
  2244. The address of a \var{absolute} directive can only point to a variable or
  2245. constant. Therefore, the following code will produce this error:
  2246. \begin{verbatim}
  2247. Procedure X;
  2248. var p : longint absolute x;
  2249. \end{verbatim}
  2250. \item [ succ or pred on enums with assignments not possible ]
  2251. When you declared an enumeration type which has assignments in it, as in C,
  2252. like in the following:
  2253. \begin{verbatim}
  2254. Tenum = (a,b,e:=5);
  2255. \end{verbatim}
  2256. you cannot use the \var{Succ} or \var{Pred} functions on them.
  2257. \item [ Array properties aren't allowed at this point ]
  2258. Indexed properties are not yet implemented.
  2259. \item [ No property found to override ]
  2260. You want to overrride a property of a parent class, when there is, in fact,
  2261. no such property in the parent class.
  2262. \item [ Only one default property is allowed, found inherited default property in class ]
  2263. You specified a property as \var{Default}, but a parent class already has a
  2264. default property, and a class can have only one default property.
  2265. \item [ The default property must be an array property ]
  2266. Only array properties of classes can be made \var{default} properties.
  2267. \item [ Internal Error in SymTableStack() ]
  2268. An internal error occurred in the compiler; If you encounter such an error,
  2269. please contact the developers and try to provide an exact description of
  2270. the circumstances in which the error occurs.
  2271. \item [ Error in type definition ]
  2272. There is an error in your definition of a new type.
  2273. \item [ Only static variables can be used in static methods or outside methods ]
  2274. A static method of an object can only access static variables.
  2275. \item [ Invalid call to tvarsym.mangledname() ]
  2276. An internal error occurred in the compiler; If you encounter such an error,
  2277. please contact the developers and try to provide an exact description of
  2278. the circumstances in which the error occurs.
  2279. \item [ illegal type declaration of set elements ]
  2280. The declaration of a set contains an invalid type definition.
  2281. \item [ Forward class definition not resolved ]
  2282. You declared a class, but you didn't implement it.
  2283. \item [ identifier idents no member ]
  2284. You specify a field of a record or object, and the record or object doesn't
  2285. contains such a field.
  2286. \item [ The use of a far pointer isn't allowed there ]
  2287. Free Pascal doesn't support far pointers, so you cannot take the address of
  2288. an expression which has a far reference as a result. The \var{mem} construct
  2289. has a far reference as a result, so the following code will produce this
  2290. error:
  2291. \begin{verbatim}
  2292. var p : pointer;
  2293. ...
  2294. p:=@mem[a000:000];
  2295. \end{verbatim}
  2296. \item [ procedure call with stackframe ESP/SP ]
  2297. A procedure doesn't need a complete stack-frame, so it is omitted.
  2298. \item [ Abstract methods can't be called directly ]
  2299. You cannot call an abstract method directy, instead you must call a
  2300. overriding child method, because an abstract method isn't implemented.
  2301. \item [ Internal Error in getfloatreg(), allocation failure ]
  2302. An internal error occurred in the compiler; If you encounter such an error,
  2303. please contact the developers and try to provide an exact description of
  2304. the circumstances in which the error occurs.
  2305. \item [ Unknown float type ]
  2306. The compiler cannot determine the kind of float in an expression.
  2307. \item [ SecondVecn() base defined twice ]
  2308. An internal error occurred in the compiler; If you encounter such an error,
  2309. please contact the developers and try to provide an exact description of
  2310. the circumstances in which the error occurs.
  2311. \item [ Extended cg68k not supported ]
  2312. \item [ 32-bit unsigned not supported in MC68000 mode ]
  2313. The cardinal type isn't supported on the MC68000 processor.
  2314. \item [ Internal Error in secondinline() ]
  2315. An internal error occurred in the compiler; If you encounter such an error,
  2316. please contact the developers and try to provide an exact description of
  2317. the circumstances in which the error occurs.
  2318. \item [ Stack limit excedeed in local routine ]
  2319. Your code requires a too big stack. Some operating systems pose limits
  2320. on the stack size. You should use less variables or try ro put large
  2321. variables on the heap.
  2322. \end{description}
  2323. \chapter{Run time errors}
  2324. The \fpc Run-tim library generates the following errors at run-time
  2325. \footnote{The \linux port will generate only a subset of these.}:
  2326. \begin{description}
  2327. \item [1 Invalid function number]
  2328. You tried to call a \dos function which doesn't exist.
  2329. \item [2 File not found]
  2330. You can get this error when you tried to do an operation on a file which
  2331. doesn't exist.
  2332. \item [3 Path not found]
  2333. You can get this error when you tried to do an operation on a file which
  2334. doesn't exist, or when you try to change to, or remove a directory that doesn't exist,
  2335. or try to make a subdirectory of a subdirectory that doesn't exist.
  2336. \item [4 Too many open files]
  2337. When attempting to open a file for reading or writing, you can get this
  2338. error when your program has too many open files.
  2339. \item [5 File access denied]
  2340. You don't have access to the specified file.
  2341. \item [6 Invalid file handle]
  2342. If this happens, the file variable you are using is trashed; it
  2343. indicates that your memory is corrupted.
  2344. \item [12 Invalid file access code]
  2345. This will happen if you do a reset or rewrite of a file when \var{FileMode}
  2346. is invalid.
  2347. \item [15 Invalid drive number]
  2348. The number given to the Getdir function specifies a non-existent disk.
  2349. \item [16 Cannot remove current directory]
  2350. You get this if you try to remove the current diirectory.
  2351. \item [17 Cannot rename across drives]
  2352. You cannot rename a file such that it would end up on another disk or
  2353. partition.
  2354. \item [100 Disk read error]
  2355. \dos only. An error occurred when reading from disk. Typically when you try
  2356. to read past the end of a file.
  2357. \item [101 Disk write error]
  2358. \dos only. Reported when the disk is full, and you're trying to write to it.
  2359. \item [102 File not assigned]
  2360. This is reported by Reset, Rewrite, Append, Rename and Erase, if you call
  2361. them with an unassigne function as a parameter.
  2362. \item [103 File not open]
  2363. Reported by the following functions : Close , Read, Write, Seek,
  2364. EOf, FilePos, FileSize, Flush, BlockRead, and BlockWrite if the file isn't
  2365. open.
  2366. \item [104 File not open for input]
  2367. Reported by Read, BlockRead, Eof, Eoln, SeekEof or SeekEoln if the file
  2368. isn't opened with Reset.
  2369. \item [105 File not open for output]
  2370. Reported by write if a text file isn't opened with Rewrite.
  2371. \item [106 Invalid numeric format]
  2372. Reported when a non-numerice value is read from a text file, when a numeric
  2373. value was expected.
  2374. \item [150 Disk is write-protected]
  2375. (Critical error, \dos only.)
  2376. \item [151 Bad drive request struct length]
  2377. (Critical error, \dos only.)
  2378. \item [152 Drive not ready]
  2379. (Critical error, \dos only.)
  2380. \item [154 CRC error in data]
  2381. (Critical error, \dos only.)
  2382. \item [156 Disk seek error]
  2383. (Critical error, \dos only.)
  2384. \item [157 Unknown media type]
  2385. (Critical error, \dos only.)
  2386. \item [158 Sector Not Found]
  2387. (Critical error, \dos only.)
  2388. \item [159 Printer out of paper]
  2389. (Critical error, \dos only.)
  2390. \item [160 Device write fault]
  2391. (Critical error, \dos only.)
  2392. \item [161 Device read fault]
  2393. (Critical error, \dos only.)
  2394. \item [162 Hardware failure]
  2395. (Critical error, \dos only.)
  2396. \item [200 Division by zero]
  2397. You are dividing a number by zero.
  2398. \item [201 Range check error]
  2399. If you compiled your program with range checking on, then you can get this
  2400. error in the following cases:
  2401. \begin{enumerate}
  2402. \item An array was accessed with an index outside its declared range.
  2403. \item You're trying to assign a value to a variable outside its range (for
  2404. instance a enumerated type).
  2405. \end{enumerate}
  2406. \item [202 Stack overflow error]
  2407. The stack has grown beyond itss maximum size. This error can easily occur if
  2408. you have recursive functions.
  2409. \item [203 Heap overflow error]
  2410. The heap has grown beyond its boundaries, ad you are rying to get more
  2411. memory. Please note that \fpc provides a growing heap, i.e. the heap will
  2412. try to allocate more memory if needed. However, if the heap has reached the
  2413. maximum size allowed by the operating system or hardware, then you will get
  2414. this error.
  2415. \item [204 Invalid pointer operation]
  2416. This you will get if you call dispose or Freemem with an invalid pointer
  2417. (notably, \var{Nil})
  2418. \item [205 Floating point overflow]
  2419. You are trying to use or produce too large real numbers.
  2420. \item [206 Floating point underflow]
  2421. You are trying to use or produce too small real numbers.
  2422. \item [207 Invalid floating point operation]
  2423. Can occur if you try to calculate the square root or logarithm of a negative
  2424. number.
  2425. \item [210 Object not initialized]
  2426. When compiled with range checking on, a program will report this error if
  2427. you call a virtal method without having initialized the VMT.
  2428. \item [211 Call to abstract method]
  2429. Your program tried to execute an abstract virtual method. Abstract methods
  2430. should be overridden, and the overriding method should be called.
  2431. \item [212 Stream registration error]
  2432. This occurs when an invalid type is registered in the objects unit.
  2433. \item [213 Collection index out of range]
  2434. You are trying to access a collection item with an invalid index.
  2435. (objects unit)
  2436. \item [214 Collection overflow error]
  2437. The collection has reached its maximal size, and you are trying to add
  2438. another element. (objects unit)
  2439. \item [216 General Protection fault]
  2440. You are trying to access memory outside your appointed memory.
  2441. \end{description}
  2442. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2443. % Assembler reader errors
  2444. \section{Assembler reader errors.}
  2445. This section lists the errors that are generated by the inline assembler reader.
  2446. They are {\em not} the messages of the assembler itself.
  2447. % General assembler errors.
  2448. \subsection{General assembler errors}
  2449. \begin{description}
  2450. \item [Divide by zero in asm evaluator]
  2451. This fatal error is reported when a constant assembler expressions
  2452. does a division by zero.
  2453. \item [Evaluator stack overflow, Evaluator stack underflow]
  2454. These fatal errors are reported when a constant assembler expression
  2455. is too big to evaluate by the constant parser. Try reducing the
  2456. number of terms.
  2457. \item [Invalid numeric format in asm evaluator]
  2458. This fatal error is reported when a non-numeric value is detected
  2459. by the constant parser. Normally this error should never occur.
  2460. \item [Invalid Operator in asm evaluator]
  2461. This fatal error is reported when a mathematical operator is detected
  2462. by the constant parser. Normally this error should never occur.
  2463. \item [Unknown error in asm evaluator]
  2464. This fatal error is reported when an internal error is detected
  2465. by the constant parser. Normally this error should never occur.
  2466. \item [Invalid numeric value]
  2467. This warning is emitted when a conversion from octal,binary or hexadecimal
  2468. to decimal is outside of the supported range.
  2469. \item [Escape sequence ignored]
  2470. This error is emitted when a non ANSI C escape sequence is detected in
  2471. a C string.
  2472. \item [Asm syntax error - Prefix not found]
  2473. This occurs when trying to use a non-valid prefix instruction
  2474. \item [Asm syntax error - Trying to add more than one prefix]
  2475. This occurs when you try to add more than one prefix instruction
  2476. \item [Asm syntax error - Opcode not found]
  2477. You have tried to use an unsupported or unknown opcode
  2478. \item [Constant value out of bounds]
  2479. This error is reported when the constant parser determines that the
  2480. value you are using is out of bounds, either with the opcode or with
  2481. the constant declaration used.
  2482. \item [Non-label pattern contains @]
  2483. This only applied to the m68k and Intel styled assembler, this is reported
  2484. when you try to use a non-label identifier with a '@' prefix.
  2485. \item [Internal error in Findtype()]
  2486. \item [Internal Error in ConcatOpcode()]
  2487. \item [Internal Errror converting binary]
  2488. \item [Internal Errror converting hexadecimal]
  2489. \item [Internal Errror converting octal]
  2490. \item [Internal Error in BuildScaling()]
  2491. \item [Internal Error in BuildConstant()]
  2492. \item [internal error in BuildReference()]
  2493. \item [internal error in HandleExtend()]
  2494. \item [Internal error in ConcatLabeledInstr()]
  2495. \label{InternalError}
  2496. These errors should never occur, if they do then you have found
  2497. a new bug in the assembler parsers. Please contact one of the
  2498. developers.
  2499. \item [Opcode not in table, operands not checked]
  2500. This warning only occurs when compiling the system unit, or related
  2501. files. No checking is performed on the operands of the opcodes.
  2502. \item [@CODE and @DATA not supported]
  2503. This Turbo Pascal construct is not supported.
  2504. \item [SEG and OFFSET not supported]
  2505. This Turbo Pascal construct is not supported.
  2506. \item [Modulo not supported]
  2507. Modulo constant operation is not supported.
  2508. \item [Floating point binary representation ignored]
  2509. \item [Floating point hexadecimal representation ignored]
  2510. \item [Floating point octal representation ignored]
  2511. These warnings occur when a floating point constant are declared in
  2512. a base other then decimal. No conversion can be done on these formats.
  2513. You should use a decimal representation instead.
  2514. \item [Identifier supposed external]
  2515. This warning occurs when a symbol is not found in the symolb table, it
  2516. is therefore considered external.
  2517. \item [Functions with void return value can't return any value in asm code]
  2518. Only routines with a return value can have a return value set.
  2519. \item [Error in binary constant]
  2520. \item [Error in octal constant]
  2521. \item [Error in hexadecimal constant]
  2522. \item [Error in integer constant]
  2523. \label{ErrorConst}
  2524. These errors are reported when you tried using an invalid constant expression,
  2525. or that the value is out of range.
  2526. \item [Invalid labeled opcode]
  2527. \item [Asm syntax error - error in reference]
  2528. \item [Invalid Opcode]
  2529. \item [Invalid combination of opcode and operands]
  2530. \item [Invalid size in reference]
  2531. \item [Invalid middle sized operand]
  2532. \item [Invalid three operand opcode]
  2533. \item [Assembler syntax error]
  2534. \item [Invalid operand type]
  2535. You tried using an invalid combination of opcode and operands, check the syntax
  2536. and if you are sure it is correct, please contact one of the developers.
  2537. \item [Unknown identifier]
  2538. The identifier you are trying to access does not exist, or is not within the
  2539. current scope.
  2540. \item [Trying to define an index register more than once]
  2541. \item [Trying to define a segment register twice]
  2542. \item [Trying to define a base register twice]
  2543. You are trying to define an index/segment register more then once.
  2544. \item [Invalid field specifier]
  2545. The record or object field you are trying to access does not exist, or
  2546. is incorrect.
  2547. \item [Invalid scaling factor]
  2548. \item [Invalid scaling value]
  2549. \item [Scaling value only allowed with index]
  2550. Allowed scaling values are 1,2,4 or 8.
  2551. \item [Cannot use SELF outside a method]
  2552. You are trying to access the SELF identifier for objects outside a method.
  2553. \item [Invalid combination of prefix and opcode]
  2554. This opcode cannot be prefixed by this instruction
  2555. \item [Invalid combination of override and opcode]
  2556. This opcode cannot be overriden by this combination
  2557. \item [Too many operands on line]
  2558. At most three operand instructions exist on the m68k, and i386, you
  2559. are probably trying to use an invalid syntax for this opcode.
  2560. \item [Duplicate local symbol]
  2561. You are trying to redefine a local symbol, such as a local label.
  2562. \item [Unknown label identifer]
  2563. \item [Undefined local symbol]
  2564. \item [local symbol not found inside asm statement]
  2565. This label does not seem to have been defined in the current scope
  2566. \item [Assemble node syntax error]
  2567. \item [Not a directive or local symbol]
  2568. The assembler statement is invalid, or you are not using a recognized
  2569. directive.
  2570. \end{description}
  2571. % I386 specific errors
  2572. \subsection{I386 specific errors}
  2573. \begin{description}
  2574. \item [repeat prefix and a segment override on <= i386 may result in errors if an interrupt occurs]
  2575. A problem with interrupts and a prefix instruction may occur and may cause
  2576. false results on 386 and earlier computers.
  2577. \item [Fwait can cause emulation problems with emu387]
  2578. This warning is reported when using the FWAIT instruction, it can
  2579. cause emulation problems on systems which use the em387.dxe emulator.
  2580. \item [You need GNU as version >= 2.81 to compile this MMX code]
  2581. MMX assembler code can only be compiled using GAS v2.8.1 or later.
  2582. \item [NEAR ignored]
  2583. \item [FAR ignored]
  2584. \label{FarIgnored}
  2585. \var{NEAR} and \var{FAR} are ignored in the intel assemblers, but are still accepted
  2586. for compatiblity with the 16-bit code model.
  2587. \item [Invalid size for MOVSX/MOVZX]
  2588. \item [16-bit base in 32-bit segment]
  2589. \item [16-bit index in 32-bit segment]
  2590. 16-bit addressing is not supported, you must use 32-bit addressing.
  2591. \item [Constant reference not allowed]
  2592. It is not allowed to try to address a constant memory address in protected
  2593. mode.
  2594. \item [Segment overrides not supported]
  2595. Intel style (eg: rep ds stosb) segment overrides are not support by
  2596. the assembler parser.
  2597. \item [Expressions of the form [sreg:reg...] are currently not supported]
  2598. To access a memory operand in a different segment, you should use the
  2599. sreg:[reg...] snytax instead of [sreg:reg...]
  2600. \item [Size suffix and destination register do not match]
  2601. In intel AT\&T syntax, you are using a register size which does
  2602. not concord with the operand size specified.
  2603. \item [Invalid assembler syntax. No ref with brackets]
  2604. \item [ Trying to use a negative index register ]
  2605. \item [ Local symbols not allowed as references ]
  2606. \item [ Invalid operand in bracket expression ]
  2607. \item [ Invalid symbol name: ]
  2608. \item [ Invalid Reference syntax ]
  2609. \item [ Invalid string as opcode operand: ]
  2610. \item [ Null label references are not allowed ]
  2611. \item [ Using a defined name as a local label ]
  2612. \item [ Invalid constant symbol ]
  2613. \item [ Invalid constant expression ]
  2614. \item [ / at beginning of line not allowed ]
  2615. \item [ NOR not supported ]
  2616. \item [ Invalid floating point register name ]
  2617. \item [ Invalid floating point constant: ]
  2618. \item [ Asm syntax error - Should start with bracket ]
  2619. \item [ Asm syntax error - register: ]
  2620. \item [ Asm syntax error - in opcode operand ]
  2621. \item [ Invalid String expression ]
  2622. \item [ Constant expression out of bounds ]
  2623. \item [ Invalid or missing opcode ]
  2624. \item [ Invalid real constant expression ]
  2625. \item [ Parenthesis are not allowed ]
  2626. \item [ Invalid Reference ]
  2627. \item [ Cannot use \_\_SELF outside a method ]
  2628. \item [ Cannot use \_\_OLDEBP outside a nested procedure ]
  2629. \item [ Invalid segment override expression ]
  2630. \item [ Strings not allowed as constants ]
  2631. \item [ Switching sections is not allowed in an assembler block ]
  2632. \item [ Invalid global definition ]
  2633. \item [ Line separator expected ]
  2634. \item [ Invalid local common definition ]
  2635. \item [ Invalid global common definition ]
  2636. \item [ assembler code not returned to text ]
  2637. \item [ invalid opcode size ]
  2638. \item [ Invalid character: < ]
  2639. \item [ Invalid character: > ]
  2640. \item [ Unsupported opcode ]
  2641. \item [ Invalid suffix for intel assembler ]
  2642. \item [ Extended not supported in this mode ]
  2643. \item [ Comp not supported in this mode ]
  2644. \item [ Invalid Operand: ]
  2645. \item [ Override operator not supported ]
  2646. \end{description}
  2647. % m68k specific errors
  2648. \subsection{m68k specific errors.}
  2649. \begin{description}
  2650. \item [Increment and Decrement mode not allowed together]
  2651. You are trying to use dec/inc mode together.
  2652. \item [Invalid Register list in movem/fmovem]
  2653. The register list is invalid, normally a range of registers should
  2654. be separated by - and individual registers should be separated by
  2655. a slash.
  2656. \item [Invalid Register list for opcode]
  2657. \item [68020+ mode required to assemble]
  2658. \end{description}
  2659. \chapter{The Floating Point Coprocessor emulator}
  2660. In this appendix we note some caveats when using the floating point
  2661. emulator on GO32V2 systems. Under GO32V1 systems, all is as described in
  2662. the installation section.
  2663. {\em Q: I don't have an 80387. How do I compile and run floating point
  2664. programs under GO32V2?
  2665. Q: What shall I install on a target machine which lacks hardware
  2666. floating-point support?
  2667. }
  2668. {\em A :}
  2669. Programs which use floating point computations and could be run on
  2670. machines without an 80387 should be allowed to dynamically load the
  2671. \file{emu387.dxe}
  2672. file at run-time if needed. To do this you must link the \var{emu387} unit to your
  2673. exectuable program, for example:
  2674. \begin{verbatim}
  2675. Program MyFloat;
  2676. Uses emu387;
  2677. var
  2678. r: real;
  2679. Begin
  2680. r:=1.0;
  2681. WriteLn(r);
  2682. end.
  2683. \end{verbatim}
  2684. \var{Emu387} takes care of loading the dynamic emulation point library.
  2685. You should always add emulation when you distribute floating-point
  2686. programs.
  2687. A few users reported that the emulation won't work for them unless
  2688. they explicitly tell \var{DJGPP} there is no \var{x87} hardware, like this:
  2689. \begin{verbatim}
  2690. set 387=N
  2691. set emu387=c:/djgpp/bin/emu387.dxe
  2692. \end{verbatim}
  2693. There is an alternative FP emulator called WMEMU. It mimics a real
  2694. coprocessor more closely.
  2695. {\em WARNING:} We strongly suggest that you use WMEMU as FPU emulator, since
  2696. \file{emu387.dxe} does not emulate all the instructions which are used by the
  2697. Run-Time Libary such as \var{FWAIT}.
  2698. {\em Q: I have an 80387 emulator installed in my AUTOEXEC.BAT, but
  2699. DJGPP-compiled floating point programs still doesn't work. Why?
  2700. }
  2701. {\em A :} DJGPP switches the CPU to protected mode, and the information
  2702. needed to emulate the 80387 is different. Not to mention that the
  2703. exceptions never get to the real-mode handler. You must use emulators
  2704. which are designed for DJGPP. Apart of emu387 and WMEMU, the only
  2705. other emulator known to work with DJGPP is Q87 from QuickWare. Q87 is
  2706. shareware and is available from the QuickWare Web site.
  2707. {\em Q: I run DJGPP in an \ostwo DOS box, and I'm told that \ostwo will install
  2708. its own emulator library if the CPU has no FPU, and will transparently
  2709. execute FPU instructions. So why won't DJGPP run floating-point code
  2710. under \ostwo on my machine?
  2711. }
  2712. {\em A} : \ostwo installs an emulator for native \ostwo images, but does not
  2713. provide FPU emulation for DOS sessions.
  2714. \chapter{A sample \file{gdb.ini} file}
  2715. \label{ch:GdbIniFile}
  2716. Here you have a sample \file{gdb.ini} file listing, which gives better
  2717. results when using \var{gdb}. Under \linux you should put this in a
  2718. \file{.gdbinit} file in your home directory or the current directory..
  2719. \begin{verbatim}
  2720. set print demangle off
  2721. set gnutarget auto
  2722. set verbose on
  2723. set complaints 1000
  2724. dir ./rtl/dosv2
  2725. set language c++
  2726. set print vtbl on
  2727. set print object on
  2728. set print sym on
  2729. set print pretty on
  2730. disp /i $eip
  2731. define pst
  2732. set $pos=&$arg0
  2733. set $strlen = {byte}$pos
  2734. print {char}&$arg0.st@($strlen+1)
  2735. end
  2736. document pst
  2737. Print out a pascal string
  2738. end
  2739. \end{verbatim}
  2740. \end{document}