Recently, Free Pascal (FPC) version 2.2.0 was released. This open source Pascal compiler has – since its initial release in 1993 – grown to be one of the most sophisticated open source compilers available today. Daily, more programmers discover FPC and develop their applications in Object Pascal. Specifically, the development of Lazarus has contributed to this phenomenon: Lazarus is a graphical open source IDE for FPC, with an extensive tool kit to design graphical (GUI) applications.
What is FPC’s strength?
For many programmers, the renewed interest in Pascal is surprising. Many
think of Pascal as an old language, no longer used, which has lost the battle with C a long time ago. Nevertheless, FPC has enough features to make it the language of choice for programmers.
The biggest advantage of FPC is that it is cross-platform. The development
of this compiler has been focused on this aspect ever since the start of the
This feature removes the need for laborious writing of complicated
Makefiles, which differ per platform, and which need to be generated with
tools like autoconf and configure: The programmer does not need to look for
all kinds of libraries: copying the compiler and the sources of the project
to another platform is sufficient for porting to a new system. Obviously,
cross compiling from one platform (say, Linux) to another (Windows is a
popular target) is also possible.
The reason Free Pascal code is portable is simple: it offers a large set of
cross-platform standard routines, bypassing the differences between Posix
and Windows API’s. While those can be simulated on other platforms, these
simulations require cumbersome libraries and installations, and often the
programs have a strange look-and-feel on the non-native platforms.
The Free Pascal compiler comes with a rich set of code libraries: The RTL
(Run-Time Library) provides basic functionality such as file-access,
classes, string manipulation and RTTI (Run-Time Type Information) for
streaming. The FCL (Free Class Library) is an object oriented library that
takes care of XML, Web programming, database access, image manipulation or a test-unit framework. As long as a programmer uses these libraries and
refrains from using system-dependent APIs, his program will not only run on
Linux, but also on Windows, Free BSD, Mac OS X, Windows CE and more.
It is self-evident that direct references to operating specific directories
such as ‘c:\program files’ or a configuration file in ‘/etc/myprog.cfg’,
are not cross-platform.
Using the FPC routines (for instance the TRegistry class) will take care of
these operating system details: The FCL knows where and how each system
stores configuration data. This almost completely removes the need for
system-specific API calls.
Graphical (GUI) applications
Graphical (Desktop) applications are the norm these days. Those are not a
problem: the IDE (Integrated Development Environment) Lazarus is designed
with the same principles in mind as when designing FPC: The LCL (Lazarus
Class Library) delivered with Lazarus makes it possible to develop desktop
applications that use the standard Windows 32 or 64 API. On Linux GTK 1 or 2 is used, and both a Qt and Carbon native layer are nearing their completion.
Using Lazarus, an application can be developed on Linux, and it will use
GTK. All that is needed to make a Windows version of this application is
supplying a compiler option: A recompile will then produce a windows
executable that works directly on any Windows version – without the need for
installing extra libraries. All that is required for this is a standard
Compiling from Windows to Linux is slightly more difficult: the compiler
needs the GNU linker to compile ELF binaries, and it needs to have a copy of
all needed libraries available. Yet the principle remains the same. To
produce windows binaries, FPC has an internal linker. This enables the
compiler to generate 64-bit Windows binaries, when the GNU utilities do not
yet have this ability. This makes FPC and Lazarus the first big open-source
compiler and IDE for Win64.
New features for Object Pascal
In the past, the FPC added several new features to the pascal language, such
as operator overloading – later also implemented by commercial compilers.
New in version 2.2 is the experimental support for generics (templates).
This can be useful when programming e.g. list classes.
FPC is a fast compiler: FPC compiles code roughly 7 times faster than for
instance GCC. This may seem to be of little importance, but it cuts down
development time. The speed of the generated code is comparable to the GCC compiler: according to the Shootout benchmarks, the FPC 2.0.4 code is 30% slower code than GCC. In contrast, FPC code uses less memory than GCC
generated code. Compared to interpreted languages, one sees that FPC code
executes 50 times faster than e.g. Ruby. The difference with PHP and Java is
smaller, but these use 14 (PHP) to 17 (Java) times more memory than FPC
One can wonder whether the speed of benchmarks says anything about real
(graphical) applications. Comparing the response of the popular Java IDE
Eclipse with the response of Lazarus will quickly convince one of the
difference. Native code remains faster than interpreted and JIT languages,
even when pre-compiled. Native code uses less memory, and is easier to
install, since no extras need to be installed on the computer of the
As remarked earlier on, Free Pascal is shipped with the RTL and FCL code
libraries. The FCL comes with components for accessing databases such as
Oracle, Firebird, MySQL, SQLite, PostgreSQL and any ODBC enabled database.
It also contains code for XML, Web Programs (CGI and Apache modules) or
access to graphical libraries such as SDL and OpenGL. Lots of Delphi
components are directly usable with Free Pascal. The ZeOS database access
components and the Indy networking components jump to mind. An increasing number of companies makes its Delphi libraries available for Lazarus and Free Pascal.
Free Pascal is a mature compiler, excellently suitable for any programming
task at hand. FPC shines especially where it concerns cross-platform
applications: the ease with which applications for Windows and Linux can be
developed is simply astonishing. On top of this the Lazarus project offers a
2-way IDE for the development of GUI (Desktop) applications, something
scarcely available for C or C++ under Linux. This domain is traditionally
reserved to interpreted languages such as Java or C#, which suffer from
problems such as excessive memory usage, slow performance and
maintainability. All in all it can be said that the combination FPC/Lazarus
is a good choice for cross-platform development.
How good is Lazarus today? I was very interested in its development back in 2000-2002, partially because Kylix utterly failed. But then I learned C and GTK and kinda never looked back. I visited the Lazarus website from time to time, but their screenshots are severely outdated: they’re still showing GTK 1 screenshots in 2007! This made me think that their development has halted or is very very slow.
Does the LCL still imitate the VCL or did they also add new things? The VCL is nice for mostly-fixed layout GUIs, but horrible for resizable dialogs because of the lack of sizers ala GTK and wxWidgets. Delphi 7 still suffers from this problem.
It’s a shame to read that generics/template support is still in development. I think that any serious modern statically typed OO programming language should support generics/templates. Don’t make me think back of the days when I had to write 3 different list classes just because I want to store different data types in it without requiring clients to cast return values.
Edited 2007-09-10 16:39