[fpc-pascal] Lack of 'volatile' a serious issue. Any other such caveats?

R. Diez rdiezmail-2006 at yahoo.de
Thu Dec 17 15:13:43 CET 2015


Hi all:

I have fond memories of Turbo Pascal and Delphi, and the latest 
FreePascal version seems promising enough. When I read that you can also 
write embedded firmware with it, I decided to have a look. I need a 
Windows and Linux GUI for my embedded firmware, and a development 
environment that can do both is pretty enticing.

The first thing I wondered is how come that not everyone is using 
FreePascal by now. After Visual Basic turned .NET and Delphi lost focus 
(the IDE became big, slow and expensive), FreePascal/Lazarus seems a 
perfect fit. What could be the reason? Only a few open-source projects 
are honest enough to have a "Caveats" or "Disadvantages" page, and 
FreePascal does not seem to be among them. The "Known Problem" page does 
not actually fit the bill.

The only thing I found when searching for "FreePascal disadvantages" was 
a general dislike of the Pascal language, which may be justified if 
there are many more gotchas like this:

   "for loop variable value reliable after loop?"
   http://lists.freepascal.org/pipermail/fpc-pascal/2015-October/045446.html

And there you go, I haven't quite started yet and I already discovered 
the first serious issue: there is no 'volatile' keyword. This matter has 
been brought up in the past, and it worries me that it has just been 
downplayed.

C's 'volatile' semantics are not perfect, but you need something along 
that line when writing multi-threaded programs, or when writing embedded 
software. If you take a look at the software libraries for STM or Atmel 
microcontrollers, you will see tons of 'volatile' (or ARM CMSIS' synonym 
'__IO') around. All of the peripheral registers are defined like that, 
and there are many of them in a modern microcontroller.

The lack of 'volatile' probably means constant paranoia and never-ending 
work-arounds when porting multithreading code to FreePascal, or when 
writing embedded software with it. From what I have seen, it also means 
that the compiler will never be able to optimise across units, 
preventing the kind of global optimisation that GCC's LTO does. If you 
haven't got the time to make sure that everything a loop needs is inside 
the same unit, LTO can make a huge difference. Or did I get the wrong 
impression from FreePascal in this area?

Maintaining your own independent compiler is hard, and I would have 
expected that FreePascal had turned to GCC or LLVM a long time ago. 
There is some effort in the LLVM front, but without 'volatile' in the 
main compiler, LLVM is probably not going to fix this issue, at least in 
the short or medium term. I had a quick look, and there does not seem to 
be any documentation about the reason why the LLVM port was started. I 
wonder what other deficiencies are lurking in the main compiler at the 
moment, because it looks like FreePascal users will have to live with 
the "traditional" compiler for a long time to come.

A few years ago and gave Lazarus a try. At the time I just wanted to 
write a small, portable GUI, and I had trouble debugging with the IDE. I 
think it uses GDB under the hood, which tends to be problematic if not 
written to perfection (I have made the same experience with Emacs, DDD 
and others). It may have to do with driving GDB with text, instead of 
using it as a library. FreePascal's text-mode IDE doesn't even have a 
webpage (or at least I haven't found one).

Things like this do not encourage trust either:

"Debugging smart linked code might not work correctly. This is due to 
the fact that no type information is emitted for smartlinked code."

Therefore, before I delve any deeper: are there any other serious 
drawbacks that I should know about before I invest more time looking at 
FreePascal?

Regards,
   rdiez



More information about the fpc-pascal mailing list