Oldham, Adam wrote:
Hey, the code I am having a problem with is more like:
TYPE PString = STRING[40]; pPString = ^PString;
VAR PPtr : pPString; ConsVers : String(15); BEGIN PPtr := @ConsVers; END.
test.pas:1425: assignment from incompatible pointer type
This code has worked with Turbo and SVS, but not GPC.
You are assigning a pointer to a String(15) in a variable of type pointer to String[40] which is not the same type.
If the other compilers don't complain, this means that they do not do enough type checking. At least in the case of TP (don't know SVS), this would be even worse since TP strings (unlike EP strings which GPC uses) don't contain a capacity field, so if write to PPtr^ afterwards, it would happily story up to 40 characters, overwriting random memory. With EP strings, the effects probably wouldn't be so bad, but I'm not sure exactly what might happen...
But to save TP's honour (at least this time ;-), I've just tested it, and TP does complain (`Type msimatch'). Of course, if you turn off `typed @ operator' (which might be the default -- don't remember), it will not complain, but then it will also allow assignment of a pointer to an integer to a pointer to a real or any other kind of nonsense...
Of course, you could type-cast (PPtr := pPString (@ConsVers)) with GPC (and BP), but then you have the dangers described above.
A proper solution (for GPC) would be to declare PPtr as ^String (pointer to any string).
Frank