<p><br>
Am 17.12.2011 16:54 schrieb "Bart" <<a href="mailto:bartjunk64@gmail.com">bartjunk64@gmail.com</a>>:<br>
><br>
> On 12/17/11, Sven Barth <<a href="mailto:pascaldragon@googlemail.com">pascaldragon@googlemail.com</a>> wrote:<br>
><br>
> > I don't know whether it's Delphi compatible, but this error was already<br>
> > there if you've used AnsiString, so it is a logical extension that this<br>
> > error also appears if String is an alias to AnsiString.<br>
> ><br>
> > And yes, the compiler won't let you write such a record (or let you even<br>
> > define a "file of" type of this record).<br>
><br>
> So, even if I am suicidal, the compiler will prevent me from shooting<br>
> myself in the foot?<br>
> (Whereas C will shoot me in the foor even if I don't want to)</p>
<p>That's the usual answer in this context: Pascal won't let you shoot yourself in the foot. :D</p>
<p>> Although I like the fact that fpc prevents this (most likely) error in<br>
> my coding, I still think the code itself is valid Pascal. It only does<br>
> not do what I expect it to do.<br>
> So, I think a warning should suffice.</p>
<p>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.</p>
<p>> {$Mode Reductio_Ad_Absurdum}<br>
><br>
> If fpc forbids it, it should also forbid this:<br>
><br>
> var<br>
> P: ^Integer;<br>
><br>
> begin<br>
> p := nil;<br>
> p^:= 1;<br>
> end.<br>
><br>
> This code is insane, but it is perfectly legal Pascal.</p>
<p>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.</p>
<p>Regards,<br>
Sven</p>