Docs: portability differences between Borland/FPC

classic Classic list List threaded Threaded
14 messages Options
Reply | Threaded
Open this post in threaded view
|

Docs: portability differences between Borland/FPC

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
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  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Docs: portability differences between Borland/FPC

Marco van de Voort
In our previous episode, Martok said:
> 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  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Docs: portability differences between Borland/FPC

Florian Klämpfl
In reply to this post by Martok
Am 18.08.2018 um 22:59 schrieb 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
> 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>

"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  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Docs: portability differences between Borland/FPC

Florian Klämpfl
Am 18.08.2018 um 23:26 schrieb Florian Klämpfl:

> Am 18.08.2018 um 22:59 schrieb 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
>> 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>
>
> "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  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Docs: portability differences between Borland/FPC

Bart-48
In reply to this post by Martok
On Sat, Aug 18, 2018 at 10:59 PM, Martok <[hidden email]> wrote:

> 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  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Docs: portability differences between Borland/FPC

Bart-48
On Sat, Aug 18, 2018 at 11:52 PM, Bart <[hidden email]> wrote:

> 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  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Docs: portability differences between Borland/FPC

Martok
In reply to this post by Florian Klämpfl
Am 18.08.2018 um 23:39 schrieb 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  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Docs: portability differences between Borland/FPC

Florian Klämpfl
Am 19.08.2018 um 01:49 schrieb Martok:
> Am 18.08.2018 um 23:39 schrieb 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  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Docs: portability differences between Borland/FPC

Martok
Am 19.08.2018 um 10:08 schrieb 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.


> 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  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Docs: portability differences between Borland/FPC

Florian Klämpfl
Am 19.08.2018 um 14:44 schrieb Martok:
>
>> 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.
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.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Docs: portability differences between Borland/FPC

Martok
In reply to this post by Marco van de Voort
Am 18.08.2018 um 23:25 schrieb 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  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Docs: portability differences between Borland/FPC

Florian Klämpfl
Am 19.08.2018 um 15:08 schrieb 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  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Docs: portability differences between Borland/FPC

Marco van de Voort
In reply to this post by Martok
In our previous episode, Martok said:
> Am 18.08.2018 um 23:25 schrieb 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:

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  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Docs: portability differences between Borland/FPC

Martok
In reply to this post by Florian Klämpfl
Am 19.08.2018 um 14:55 schrieb Florian Klämpfl:
> 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  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal