[fpc-pascal] Incompatible types: got "SYSTEM.PChar" expected "SYSTEM.PChar"

Sven Barth pascaldragon at googlemail.com
Thu Jun 9 08:04:08 CEST 2016


Am 09.06.2016 00:05 schrieb "José Mejuto" <joshyfun at gmail.com>:
> -----------------------
> program testpossiblebug;
>
> type
>   TFirstRecord=record
>     Ident: pchar;
>   end;
>
> const
>   TSomePcharArray: array [0..1] of pchar = ( 'pcharONE','pcharTWO');
>
> {$DEFINE THISDONTCOMPILE}
>
>   TConstRecord: TFirstRecord = (
>   {$IFDEF THISDONTCOMPILE}
>     Ident: TSomePcharArray[1]
>   {$ELSE}
>     Ident: @TSomePcharArray[1]
>   {$ENDIF}
>   );
>
> var
>   R: TFirstRecord;
>
> begin
>   R:=TConstRecord;
>   {$IFDEF THISDONTCOMPILE}
>   writeln(R.Ident);
>   {$ELSE}
>   writeln(PPchar(R.Ident)^);
>   {$ENDIF}
> end.
> ------------------------
>
> This does not compile and outputs the funny error in the subject. I think
it should compile as information is static and previously defined, but if
it is indeed an error by my side maybe the error message should be a bit
different :-?
>
> To test the example, define or undefine the "THISDONTCOMPILE", with it
defined it does not compile, without it it compiles and the modified
writeln shows the expected pchar string.
>
> Should I report it ?

One can only use untyped constants to initialize other constants or
variables in their declarations. The TsomePCharArray is a typed constant,
thus not suitable for assignments (a pointer to it's element is however
legal as you noticed).

Don't know how easy it would be to print a better error message...

Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20160609/1c4406e6/attachment.html>


More information about the fpc-pascal mailing list