pascal

Trying to assign a pointer of the same type says Type mismatch in Pascal?


I have two different variables defined as ^Byte as in:

var 
  P1 : ^Byte;
  P2 : ^Byte;

Yet when I I try:

P1:=P2;

it says Type mismatch yet I can do:

P1:=Pointer(P2);

Coming from C, I don't get it? Wouldn't P1 and P2 be the value of the pointer and when you want to access what it points to you would use P1^ and P2^ and if you use @P1 or @P2 you are getting the address to the pointer variable itself?

What am I missing?


Solution

  • Afaik in classic (70's) standard pascal this should work. But Turbo Pascal adn Delphi and derivatives went a different route, and consider both ^byte's declaration of new separate types.

    Solution: declare pbyte = ^byte; and use pbyte everywhere. If you are using a recent Delphi or Free Pascal, pbyte is already predefined or in unit types.