A lot of language battles and flame wars start by criticizing Pascal for its large file size, when the actual application is simple. For example a hello world application being 175KB, while C using GCC produces a 8.6KB executable. Pascal is capable of creating smaller files than the 175KB behemoth. Let's go over 1 change which make your Pascal Executable Size smaller.
First let's get some proof of this size difference. First up the screenshot of the Pascal file size's on my machine.
And now to see what a C compiler is capable of.
Why is Pascal Generating a Large Binary
I think the best place to start is understanding what is happening. GCC and LD by default do some work to strip out unused code. FreePascal (FPC) on the other hand, default to leaving all of the unused stuff. Improving compilation speed. Admittedly, compilation speed of smaller projects isn't an issue anymore.
Second, Pascal is including a lot of Runtime code directly in the executable. This means that you don't need a C or C++ runtime DLL, DYLIB, or SO of your machine to run pascal programs. Anyone who has had issues with Games or Game Development on Windows knows exactly what I am talking about here. Well, Pascal statically links the runtime into your application. (It is actually a little faster execution this way)
There are other things contributing to this too, but let's skip that and start with the Size Reduction. Maybe we can go into more details about the stuff in an Executable from Pascal later.
1. Strip Unused Code
Since FPC doesn't strip symbols and unused code by default, we need to tell it to do this during compilation.
$ fpc -Xs -XX hello.pas
This will generate a hello executable just about 26KB large. This is a huge reduction from the initial default size.
Need help with Pascal or Legacy Software?
If you need help with legacy software, especially software written in Pascal (TurboPascal, MacPascal, Delphi, or others). I would love to help. I am an independent contractor/consultant and always on the lookout for legacy rewrites or maintenance. Please fill out the form below or use the information in the Connect with me section of the footer.
//TODO: Add for here