[LinuxFocus-icon]
LinuxFocus article number 356
http://linuxfocus.org

[Photo of the Author]
by Razmal Djamal (homepage)

About the author:

I am a big Open Source fan. I like the way they are working together without seeing each others. And it's wonderfull to make our knowledge available as a free resource to all people around the world. We become one world, one universe without restrictions in terms of race, nation or religion. I'm doing my job on various system, but i preferre Linux. I'm a Linux nomade, moving around and I am interested in many things ... but i like most to write code ... especially in Pascal and Python. I am a moslem, thus I am adoring my great prophet Muhammad SAW ...and the best regards to him, and may Allah SWT. All love, salvation and all promises to him.



Translated to English by:
Razmal Djamal (homepage)

Get To Know A Free Pascal Compiler : Free Pascal

[The Free Pascal Logo and The Jaguar is courtesy of FreePascal.org]

Abstract:

Many of you might remember the legendary Turbo Pascal. After that the RAD (Rapid Application Development) tools named Delphi And Kylix (for Linux) came and then programming languanges similar to Pascal syntax. Basic ASCII text based Pascal languages are almost gone today. Now Free Pascal is on the rise with a combination of text mode programming and OOP as powerfull as RAD Delphi.

_________________ _________________ _________________

 

Introducing

Free Pascal is a free compiler for Pascal syntax languanges, semantically similar and compatible with Borland Turbo Pascal 7, the latest legendary Turbo Pascal. It comes with a lot of powerful features and is like a combination of TP7 and Object Pascal from Delphi. Right now, the Free Pascal development team is working hard to make a better compiler for cross platform usage. You can download all kind platform of installation packages from [1].  

Minimum requirements

Free Pascal is able to run on a 386 prosessor. But I preferre to use some processor like 486 and upwards. AMD CPUs are of course also working as they are all compatible with the 386. Free pascal can also run on the Motorola processor. At least you must have a 680x0 or 68020 to make it work. On every platform, I recommended at least 8 Megabytes of RAM, it will even work with only 4 Megabytes of RAM. With regards to disk space you need minimum 25 Megabytes for the installation. This compiler is available for various operating systems. The latest news is that it is now available for sparc, AMD 64, and arm/linux. If you are interested to know how many platforms Free Pascal is ported to, you may go to download page on [1]. There are packages for Linux, Win32, Amiga, Dos, QNX,Solaris, BeOS, NetBSD,FreeBSD, and OS2.

 

Why Pascal,..Why Free Pascal ?

On Linux, most people just like to use C, since the kernel is write in C. So why you have to learn Pascal? I am already fluent in C, but there are so many perfect ways of writing code in Pascal. It is very clear. It is very fast, doesn't need any make file, it is very structured, you'll know preciselly whether is a code block, a procedure, or a function. The compilers are really really fast, even when you are compiling a big file. One thing that I admire is its great integration with assembler. Years ago Pascal was known to produce well readable assembly code.For Linux compatibilty, FPC (Free Pascal Compiler) has great features, once you have done one program using Linux FPC compiler, then it will be able to run on any kind of linux machine. It's really cool!! It is distribution independent. Furthermore, FPC is very compatible with any kind of Pascal. Like TP7, GnuPascal, even with Delphi and Kylix. You can use your code you've writen with any of them. The last improvement is that it supports now OOP, just like Delphi and Kylix, great. For somebody who knows Object Pascal it is very easy. There is no different between them, whether it is code syntax, or the powerful features.

FPC has a great advantage too ..it is like an IDE (Integrated Development Environment) that is very similar to TP7. I can't talk about the advantages long enough ...this compiler is able to do a database programming. You can connect to great SQL servers like MySQL and PostgreSQL, even Interbase. With regards to the GUI FPC can be integrate with widgets like GTK, Tcl/Tk, and ncurses. So..Why Free Pascal...Why not ?!!

 

Straight to the installation

Since i wrote this article for a free Linux Magazine, then i'll take the installation for Linux the environment. You'll need one installation packet for linux x86. Simply grab the rpm package from the download page. The latest version is the beta release 1.9.4 aka 2.0.0-Beta3. The installation packages come with a unique name, for example fpc-1.0.10.i386.tar; You have to un-tar this file. Simply type this command:

[root@yourlinuxbox /]tar xvf fpc-1.0.10.i386.tar
This command will extract the following files :

To install Free Pascal, just type on your fpc directory as a root :
[root@yourlinuxbox /]#sh install.sh
or
[root@yourlinuxbox /]#./install.sh
This command will install your fresh fpc to the default directory, but in this process you will get many question about path and location of several files. It ended succesfully when you see this:
Writing sample configuration file to /etc/fpc.cfg
End of installation.
Refer to the documentation for more information.

The installation, will create some new directories that are very usefull for beginenrs:


Now you can enjoy to write in an excellent very structured, high level programming languange..!

 

Hello World

Next, we will try to write the famous example code called "Hello World". To make this, it doesn,t take much time or code, you just need to create a file with extension pp or pas. So open your favorite editor and enter this:

  begin
    Writeln('Hello World From Pascal..!!');
  End.
Save this file to "hello.pas". Then we go to the compile process. To Compile this file simply type a command:
  fpc test.pas
To run the output (incredibly, the output from compile process is a binary file!!). A picture is better than thousand words so here is the compile process and the ourput of the binary file:

Since the output is a binary file, it mean this file is executable. This file are distribution independent, you dont have to compile it on any linux machine you may want to distribute this file. The above example will give you the same result, even you compiled it on Windows 98, without changing any code. This is ofcourse only possible because we do not use operating system specific functionallity.

 

Summary

Free pascal is ready for use in production. It is as good (if not better) than commercial products. The advantage is that this one is free. It gives you more flexibility and saves cost (no license fees). Free Pascal is a swiss army knife. You can develop linux programs easier than ever before. Its a worth of try..believe me.. The plan is to start a series about programming in FPC and I hope that many of you will join me in writing clean code with an clean and structured compiler.

 

Links



Webpages maintained by the LinuxFocus Editor team
© Razmal Djamal
"some rights reserved" see linuxfocus.org/license/
http://www.LinuxFocus.org
Translation information:
id --> -- : Razmal Djamal (homepage)
id --> en: Razmal Djamal (homepage)

2005-01-15, generated by lfparser_pdf version 2.51