By default, Free Pascal follows Turbo Pascal in making
integer
a 16-bit type. However, when using a 32-bit
machine, arithmetic with 16-bit integers is actually slower
than with 32-bit integers. Using longint
also reduces the
chance of an arithmetic overflow. Since it is such habit to use
integer
, it may be worth doing a global search and replace
after you have finished code to make you that you are using
longint
everywhere.
One place where you might not want to use longint
is in
large arrays. Here longints
use more memory. This also
slows things down, because it wastes memory bandwidth and cache space.
However, it is not a huge slowdown and you should consciously think
about whether you need to use a smaller data type before doing so.
Free Pascal supports a data type that Turbo Pascal does not:
int64
, a signed 64-bit integer. This supports very large
integers, up to 263-1 or 9223372036854775807.
Both Free Pascal and Turbo Pascal support compiler directives for checking various types of errors. The two most important ones are
$R+
Range checking. This checks that you are not
accessing array elements out of bounds, and catches some cases of a
number being too big for its data type.$Q+
Overflow checking. This catches arithmetic
operations that generate a number too large for the result variable.These will slow your program down a lot, but are incredibly useful in catching bugs early. This is one of the few advantages Pascal programmers have at an olympiad, and you should put it to use. Turn these flags on while writing and testing your program. Turn them off only if you need to test the speed of your program, and to hand in. Do not forget to take them out when handing in, otherwise your program will run very slowly during evaluation.
While all Pascal programmers will be familiar with the
readln
function, many do not know that the
read
function can be very handy for reading text files. If
you have a file full of numbers, then read
can be used to
read in the next one - whether it is separated by a space or a newline
from the previous one.
Last updated Sat May 31 19:49:31.0000000000 2008. Copyright Bruce Merry (bmerry '@' gmail dot. com).