user.tex 117 KB

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