Re: [fpc-devel] {$mode tp} compatibility issue
On Tue, 5 Jun 2018 14:09:16 +0200 Klaus Hartnegg wrote: > Hi, > > I just stepped into a trap when compiling Turbo Pascal source with > FreePascal, and wonder how FreePascal could prevent this. > > The source effectively contains something like > > type >mytype = (a,b,c); > > var >t : mytype; >f : text; > > begin >assign (f,'filename'); >reset (f); >readln (f,byte(t)); > > Except that in the real thing the type declaration was in another unit, > but that should not matter, right? It does matter. See here: https://www.freepascal.org/docs-html/prog/progsu59.html#x66-650001.2.59 Mattias ___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
Re: [fpc-devel] {$mode tp} compatibility issue
In our previous episode, Klaus Hartnegg said: > > Could FreePascal check that variables like "mytype = (a,b,c)" have size > 1 before using them in {$mode tp}? Otherwise they should be flaged as > incompatible type, to prevent such surprises. Not really, better edit your project to make sure that everything is forced TP if you work exclusively in TP mode. ___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
[fpc-devel] {$mode tp} compatibility issue
Hi, I just stepped into a trap when compiling Turbo Pascal source with FreePascal, and wonder how FreePascal could prevent this. The source effectively contains something like type mytype = (a,b,c); var t : mytype; f : text; begin assign (f,'filename'); reset (f); readln (f,byte(t)); Except that in the real thing the type declaration was in another unit, but that should not matter, right? Well, sometimes I got t > high(mytype), eventhough the file contents guaranteed that this could not happen. It took me a while until I found the cause: The last statement can only be compiled with {$mode tp}, so I had added that. But the unit, where mytype was declared, did not have {$mode tp}. Thus sizeof(t)=4, which does not resonate well with byte(t). The read statement modifies only one of the four bytes. In Turbo Pascal such variables have only one byte. Miracle solved, but somehow this should not happen. Could FreePascal check that variables like "mytype = (a,b,c)" have size 1 before using them in {$mode tp}? Otherwise they should be flaged as incompatible type, to prevent such surprises. thanks, Klaus ___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel