Martin Liddle wrote:
ml3.p:17: passing arg 1 of 'File_is_writable' from incompatible pointer type'
Program ml3; uses gpc;
Type tfchar=File of Char; Var Dev:TFChar;
function file_is_writable(fileptr:PAnyFile):boolean; var b:bindingtype; begin (*file_is_writable*) b:=binding(fileptr^); file_is_writable:=(b.bound and b.writable); end; (*file_is_writable*)
begin Rewrite(Dev,'/dev/ttyS0'); if file_is_writable(Addr(dev)) then begin Writeln('OK'); end; end.
It compiles and runs with gpc 20020426. Is this a deliberate change or another bug?
It's a known bug (and actually known for a longer time, so I'm surprised it worked in 20020426, maybe another bug there ...).
The problem is that `AnyFile' is not really implemented yet (syntactically), and currently it's just equivalent to `Text'. However, a type-cast from any file type to `AnyFile' is explicitly safe for the built-in `AnyFile' routines, so you can write (for now):
if file_is_writable(PAnyFile(Addr(dev))) then
Alternatively, the option `--no-typed-address' (`{$T-}') will make the result of `Addr' an untyped pointer. This will also work here, but is generally much more risky, since it will allow any kind of type mismatch with `Addr' (and `@').
BTW, I just noted that in BP `Addr' always yields an untyped pointer (unlike `@'), even with `{$T+}'. I'll change this, but only in `--borland-pascal' mode.
Frank