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.
Thanks, Adam
-----Original Message----- From: Frank Heckenbach [mailto:frank@g-n-u.de] Sent: Friday, February 23, 2001 8:51 PM To: gpc@gnu.de Subject: Re: Strings, Lengths, etc
Oldham, Adam wrote:
Also, if I have a String[15] and String[20] and I want to assign a
variable
with the value in string15, is there a way to get the compiler to not complain that the types are different?
What do you mean? Assigning between strings of different capacity works without any warning or error:
program Foo;
var Foo: String (15); Bar: String (20);
begin Foo := Bar; Bar := Foo end.
Frank
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
"Oldham, Adam" a écrit :
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.
But the behaviour of gpc is logical in this case, TP and SVS are not.