user.tex 119 KB

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