Discussion:
[fpc-pascal] Docs: portability differences between Borland/FPC
Martok
2018-08-18 20:59:55 UTC
Permalink
Hi all,

There is the old "Porting TP" document at <https://www.freepascal.org/port.var>, but it is rather incomplete (and probably on an
older language level). It also covers mostly syntactic differences - things a programmer will notice because of the error messages.

Since #34140 was again someone tripping over an obscure difference between what is documented for the Borland compilers and what
is not actually documented in FPC (there's a reason #16006 has so many dupes), I've started writing up some of these things that
I could think of right away on the wiki, for now as a draft under my user namespace:
<http://wiki.freepascal.org/User:Martok/Portability_Issues>

Feel free to suggest more non-obvious topics (or make additions directly, it's a wiki). The general pattern for each topic is
"short summary"-"example"-"contrast"-"links". Include citations if possible, especially for the Borland side of things. FPC is
easy enough to reproduce for everybody.
--
Regards,
Martok

_______________________________________________
fpc-pascal maillist - fpc-***@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/li
Marco van de Voort
2018-08-18 21:25:13 UTC
Permalink
Post by Martok
There is the old "Porting TP" document at
<https://www.freepascal.org/port.var>, but it is rather incomplete (and
probably on an older language level). It also covers mostly syntactic
differences - things a programmer will notice because of the error
messages.
Summary: behaviour with range checks off is implementation defined?

_______________________________________________
fpc-pascal maillist - fpc-***@lists.freepascal.org
http://lists.freepascal.org/c
Martok
2018-08-19 13:08:49 UTC
Permalink
Post by Marco van de Voort
Summary: behaviour with range checks off is implementation defined?
No. "implementation different", but not really "implementation defined".

TP and Delphi are fully defined without range checks. In fact, TP is defined as
*having no runtime range checks at all* (TP7LG, Chapter 21), except for
Succ/Pred (and Inc/Dec by extension), which explicitly react to $R (TP7LG,
Chapter 4) . One might imagine:

function Succ<T: Ordinal>(X: T): T; inline;
begin
Result:= T(Ord(X) + 1);
{$IFOPT RANGECHECKS}
if Result > High(T) then
RuntimeError(201);
{$ENDIF}
end;

{Mentioned for completeness: method checks (our -CR) are also handled by $R}


ISO 7185 has mandatory range checks (as "dynamic violations"), but whether
adhering to a 30-year-old incredibly badly written standard that was obsolete at
publication (while at the same time implementing features of a far better
language) is a good idea I would seriously consider debatable.



But I don't actually want to debate that here, just collect information for users.


_______________________________________________
fpc-pascal maillist - fpc-***@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/
Florian Klämpfl
2018-08-19 13:14:59 UTC
Permalink
Post by Martok
But I don't actually want to debate that here, just collect information for users.
Well, you have to as you give people the wrong impression that they can control what happens if they suppress/ignore run
time errors.
_______________________________________________
fpc-pascal maillist - fpc-***@lists.freepascal.org
http://lists.freepascal.org/c
Florian Klämpfl
2018-08-18 21:26:38 UTC
Permalink
Post by Martok
Hi all,
There is the old "Porting TP" document at <https://www.freepascal.org/port.var>, but it is rather incomplete (and probably on an
older language level). It also covers mostly syntactic differences - things a programmer will notice because of the error messages.
Since #34140 was again someone tripping over an obscure difference between what is documented for the Borland compilers and what
is not actually documented in FPC (there's a reason #16006 has so many dupes), I've started writing up some of these things that
<http://wiki.freepascal.org/User:Martok/Portability_Issues>
"For example in Delphi, Percentile above is a Subrange of the Host Type Integer, so it could contain any value of a
32bit Integer."

This is plainly wrong, at least for the older delphis, the host type in delphi will be Byte (or even Shortint). Please
note also, that Delphi shows exactly the same behavior as FPC if you replace 99 by 255.
_______________________________________________
fpc-pascal maillist - fpc-***@lists.freepascal.org
http://lists.freepa
Florian Klämpfl
2018-08-18 21:39:28 UTC
Permalink
Post by Florian Klämpfl
Post by Martok
Hi all,
There is the old "Porting TP" document at <https://www.freepascal.org/port.var>, but it is rather incomplete (and
probably on an
older language level). It also covers mostly syntactic differences - things a programmer will notice because of the
error messages.
Since #34140 was again someone tripping over an obscure difference between what is documented for the Borland
compilers and what
is not actually documented in FPC (there's a reason #16006 has so many dupes), I've started writing up some of these
things that
<http://wiki.freepascal.org/User:Martok/Portability_Issues>
"For example in Delphi, Percentile above is a Subrange of the Host Type Integer, so it could contain any value of a
32bit Integer."
This is plainly wrong, at least for the older delphis, the host type in delphi will be Byte (or even Shortint).
It is actually shortint ...
_______________________________________________
fpc-pascal maillist - fpc-***@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-p
Martok
2018-08-18 23:49:23 UTC
Permalink
Post by Florian Klämpfl
Post by Florian Klämpfl
This is plainly wrong, at least for the older delphis, the host type in delphi will be Byte (or even Shortint).
It is actually shortint ...
Correct, I was thinking of the default PackEnum. Which of course has absolutely
nothing to do with that example.

Fixed, thanks.

_______________________________________________
fpc-pascal maillist - fpc-***@lists.freepascal.org
http://lists.freepascal.
Florian Klämpfl
2018-08-19 08:08:11 UTC
Permalink
Post by Martok
Post by Florian Klämpfl
Post by Florian Klämpfl
This is plainly wrong, at least for the older delphis, the host type in delphi will be Byte (or even Shortint).
It is actually shortint ...
Correct, I was thinking of the default PackEnum. Which of course has absolutely
nothing to do with that example.
Fixed, thanks.
Not really, you have also to fix the comments below because as soon as the range is 0..127 and the test is against 127,
Delphi shows exactly the same behavior as FPC.
_______________________________________________
fpc-pascal maillist - fpc-***@lists.freepascal.org
http://lists.freepascal.org/cgi
Martok
2018-08-19 12:44:29 UTC
Permalink
Post by Florian Klämpfl
Not really, you have also to fix the comments below because as soon as the range is 0..127 and the test is against 127,
Delphi shows exactly the same behavior as FPC.
Not really. You don't have to change the range, there is a warning emitted for
the Host Type (I>127 in this case), but codegen works on the worst-case scenario
for the Storage Type, so the expression is never removed. In other words, W1021
is never treated as the same as an actual False constant.
Post by Florian Klämpfl
as soon as [something changes], Delphi shows exactly the same behavior as FPC.
But that's kind of the point of this collection: sometimes the rules intersect,
but for most cases, they don't.

_______________________________________________
fpc-pascal maillist - fpc-***@lists.freepascal.org
http://lists.freepascal.org/cgi-bin
Martok
2018-08-19 13:23:29 UTC
Permalink
Please note again: in general, there are no defined rules for FPC as soon as range check errors would occur. For FPC,
you are just documenting random *behavior* which might change even with the next minor release.
I know. And I have given up trying to change your mind about that ;-)

Even if the takeaway lesson in the future will be just "it used to be like this,
better check what is current", then that is still better than the state today. I
know this is consistent for you, you've been at this for "a few" years. Coming
from Borland, that is a major unseen difference. The other way around is far easier.
Well, you have to as you give people the wrong impression that they can control what happens if they suppress/ignore run
time errors.
Okay, I've moved that paragraph to it's own section.

_______________________________________________
fpc-pascal maillist - fpc-***@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pas

Bart
2018-08-18 21:52:27 UTC
Permalink
Post by Martok
There is the old "Porting TP" document at <https://www.freepascal.org/port.var>, but it is rather incomplete (and probably on an
older language level). It also covers mostly syntactic differences - things a programmer will notice because of the error messages.
{ Continued from above }
if I > 99 then
Writeln('This is not a Percentage')

Borland
Does exactly what is written.

TurboPascal 6.0 will not do that. It will execute the else statment if
there is one. (example compiled with {$R-})
if I > 99 then
Writeln('This is not a Percentage')
else
writeln('I = ',I);

It will print: I = 100

Tested with TP 6.0 on FreeDos 1.2

Bart
_______________________________________________
fpc-pascal maillist - fpc-***@lists.freepascal.org
http://lists.freepascal.
Bart
2018-08-18 21:56:42 UTC
Permalink
Post by Bart
TurboPascal 6.0 will not do that. It will execute the else statment if
Just ignore my above post.
Made a typo in the if condition....

Bart
_______________________________________________
fpc-pascal maillist - fpc-***@lists.freepascal.org
http://lists.freepascal.o
Marco van de Voort
2018-08-19 13:18:42 UTC
Permalink
Post by Martok
Post by Marco van de Voort
Summary: behaviour with range checks off is implementation defined?
No. "implementation different", but not really "implementation defined".
TP and Delphi are fully defined without range checks. In fact, TP is defined as
*having no runtime range checks at all* (TP7LG, Chapter 21), except for
Succ/Pred (and Inc/Dec by extension), which explicitly react to $R (TP7LG,
Well TP has a conservative codegenerator because its simplicity. Delphi is
heavily versioned, and testing all versions using all options is hard.

... and then even you are not certain it is really intended.
_______________________________________________
fpc-pascal maillist - fpc-***@lists.freepascal.org
http://lists.freepascal.org/cgi-bin
Loading...