[Lazarus] *** GMX Spamverdacht *** Re: FW: Re: more file operation problems

Sven Barth pascaldragon at googlemail.com
Sat Dec 17 19:51:45 CET 2011


Am 17.12.2011 16:54 schrieb "Bart" <bartjunk64 at gmail.com>:
>
> On 12/17/11, Sven Barth <pascaldragon at googlemail.com> wrote:
>
> > I don't know whether it's Delphi compatible, but this error was already
> > there if you've used AnsiString, so it is a logical extension that this
> > error also appears if String is an alias to AnsiString.
> >
> > And yes, the compiler won't let you write such a record (or let you even
> > define a "file of" type of this record).
>
> So, even if I am suicidal, the compiler will prevent me from shooting
> myself in the foot?
> (Whereas C will shoot me in the foor even if I don't want to)

That's the usual answer in this context: Pascal won't let you shoot
yourself in the foot. :D

> Although I like the fact that fpc prevents this (most likely) error in
> my coding, I still think the code itself is valid Pascal. It only does
> not do what I expect it to do.
> So, I think a warning should suffice.

It is valid Pascal as long as the types used aren't managed ones like
dynamic arrays, ansistrings and widestrings. But as soon as you use such a
type it isn't valid anymore in the context of file I/O. "String" is a
hybrid here, because depending on a compiler option it can be legal Pascal
or not.

> {$Mode Reductio_Ad_Absurdum}
>
> If fpc forbids it, it should also forbid this:
>
> var
>  P: ^Integer;
>
> begin
>  p := nil;
>  p^:= 1;
> end.
>
> This code is insane, but it is perfectly legal Pascal.

This is a different situation. Here the compiler would need to track the
contents of variables when compiling (which is possible in theory - I'm
hearing a lecture about this in the current term), while in the file case
it's just simple type checking which the compiler does anyway.

Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20111217/a9c0ef2b/attachment-0003.html>


More information about the Lazarus mailing list