[fpc-pascal] possible bug in blockwrite

Bart bartjunk64 at gmail.com
Sun Mar 5 23:00:08 CET 2023


On Sun, Mar 5, 2023 at 7:02 PM Travis Siegel via fpc-pascal
<fpc-pascal at lists.freepascal.org> wrote:

> On tp, I could open a file with a blocksize of 1,
>
> reset(file1,1);
>
...

> For example.
>
> Let's say I have a 5 byte string:
>
> st1 := '12345';
>
> Now, if I blockwrite this to the file under tp:
>
> blockwrite(f1,st1);

That will not compile under TP (tested with TP 6.0)
It needs a third parameter "count".

...

> blockwrite(f1,st1,6);

>
> The reason it needs the extra byte is because the byte 0 (the one that
> stores the size of the string) is also written to the file. TP did not
> behave this way, though I don't know about delphi, though I'd doubt it dit.

TP also does this, just tested.
The first byte in the file is $05.

Normally one would do
BlockWrite(f, S[1], Length(S));

> Is this a bug, or is this a deliberate design decision, and if so, can
> we talk about changing it's behavior?

Your memory just serves you wrong.

...

> st1 := #49+#50+#51+#13;
>
> then the same code:
>
> val(st,number,code);
>
> produces an error, and code has the value of 4, (the place in the string
> where the error occurred), but number has a value of 0.
>
> In tp, number would still have a value of 123, because it would simply
> ignore the carriage return at the end of the string.

In TP 6.0, code is set to 4 and number to zero (but the value of
number shall be undefined if code <> 0)

Again, your memory serves you wrong....

-- 
Bart


More information about the fpc-pascal mailing list