Am 26.10.2019 um 14:56 schrieb Ryan Joseph:

On Oct 26, 2019, at 4:26 AM, Sven Barth via fpc-pascal 
<fpc-pascal@lists.freepascal.org> wrote:

CodePointer(Py_Initialize) := GetProcAddress(handle, 'Py_Initialize');
Thanks that works.

I don’t think I’ve ever cast a left side value before in Pascal and honestly I 
didn’t think it was even possible. In fact didn’t we just have a big talk about 
for loop iterators and how they can’t be type cast? I thought that was because 
casting the left side value was illegal. Very confused now. ;)
The for-in loop works *because* casting the left side of an assignment is legal. If it wouldn't be legal there wouldn't have been any discussion, because then the bug wouldn't be there. The compiler simply transforms

=== code begin ===

for x in y do begin
  // ...
end;

=== code end ===

into

=== code begin ===

tmpenum := y.GetEnumerator;
while tmpenum.MoveNext do begin
  x := tmpenum.Current;
  // ...
end;

=== code end ===

Thus "for cast(x) in y" simply becomes the ordinary assignment "cast(x) := tmpenum.Current", which is why the compiler does not complain currently.

However a for-loop does not have an assignment in the usual sense for the loop-variable, thus the following is not legal:

=== code begin ===

var
  i: smallint;
begin
  for word(i) := 0 to 15 do ;
end.

=== code end ===

Regards,
Sven
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to