[fpc-pascal]Apple Mac pointer problem
Harald Houppermans
houppermans at home.nl
Fri Sep 24 03:33:25 CEST 2004
----- Original Message -----
From: "Harald Houppermans" <houppermans at home.nl>
To: <fpc-pascal at lists.freepascal.org>
Sent: Friday, September 24, 2004 3:19 AM
Subject: Re: [fpc-pascal]Apple Mac pointer problem
>
> ----- Original Message -----
> From: "Harald Houppermans" <houppermans at home.nl>
> To: <fpc-pascal at lists.freepascal.org>
> Sent: Friday, September 24, 2004 3:06 AM
> Subject: Re: [fpc-pascal]Apple Mac pointer problem
>
>
> >
> >
> >
> > ----- Original Message -----
> > From: "Stephen Downs" <stephend at e-tempest.co.uk>
> > To: <fpc-pascal at lists.freepascal.org>
> > Sent: Thursday, September 23, 2004 8:49 PM
> > Subject: [fpc-pascal]Apple Mac pointer problem
> >
> >
> > I am porting a Mac CodeWarrior project to FreePascal and have hit a
> > compile problem with a pointer. In my original code I have a structure
> > defined along the lines of
> >
> > testData = record
> > testIndex : array [0..12] of integer;
> > end;
> >
> > testDataPointer = ^testData;
> > testDataHandle = ^testDataPointer;
> >
> > Within my main code I open a file and try to read it into my structure
> >
> > testDataHdl := testDataHandle(NewHandleClear(sizeof(testData)));
> > OSError := FSRead(fileRefNum, numberOfBytes, testDataHdl^)
> >
> > The FSRead line fails with error: 62: Incompatible type for arg no. 3:
> > Got "testDataPointer", expected "Ptr" - the third parameter for FSRead
is
> a
> > pointer. I presume this is because FreePascal uses typed pointers. I
> > tried replacing testDataHdl^ by Ptr(testDataHdl)^ but that gives a
> > similar error - Got "ShortInt", expected "Ptr"
> >
> > Does anyone know how I can get around this?
> >
> > regards... Steve
> >
> > Euhm... just my two cents:
> >
> > testDataHdl is in fact a pointer to a pointer to data.
> >
> > so testDataHdl^ points to a pointer.
> >
> > If you want to read a pointer from the file that's good.
> >
> > But if you actually want to read the data then it's a mistake.
> >
> > Then you need to use this:
> >
> > testDataHdl^^
> >
> > Bye,
> > Skybuck.
> >
>
> Though euhm.. it depends on the way the routine really works.
>
> It seems it's excepting pointers.
>
> So testDataHdl^ seems correct... since that will supply the routine with a
> pointer to the data.
>
> Maybe the prototype is incorrect ?
>
> You can always try testDataHdl^^ and see if it works ;) lol.
>
> Though looking at the code again... why is testDataPointer declared (it
> doesn't seem to be used) ?
>
> In other words...
>
> 1. Does the routine expect a pointer to data ?
> 2. Does the routine expect a pointer to a pointer to data ?
> 3. Or does the routine expect like a var parameter... that means the data
> itself... like a const reference or something ;)
>
> For example pascal and delphi file routines and streams work with number 3
> ;)
>
> In your case it seems the routine work with number 1.
>
> That means testDataHdl^ is simply a mistake.
>
> Since you are now dereferencing it to the data.
>
> The routine doesn't want the data... the routine wants a pointer.
>
> So the correct call is probably something like:
>
> OSError := FSRead(fileRefNum, numberOfBytes, testDataHdl )
>
> testDataHdl (without the hat ^ )
>
> The funny thing is the declaration of the testDataPointer put you, me and
> everybody else off ;)
>
> It's simply misleading :)
For a second there... I thought testDataHdl is a pointer to data...
But my first posting was correct... it's a pointer to a pointer to data.
Are you sure you want that ?
Maybe you should try changing the declarion from:
testDataHandle = ^testDataPointer;
to this:
testDataHandle = ^testData;
Now the type points directly to the data.
And then the routine call should probably be:
OSError := FSRead(fileRefNum, numberOfBytes, testDataHdl )
So the real problem with your code... might be that it is missing a piece of
allocated memory.
test data is probably allocated
test data handle pointer is allocated.
but the pointer in between is missing.
+----------------+ +-----------------+ +----------+
| test data handle | ->| test data pointer | -> | test data |
+----------------+ +-----------------+ +----------+
( By changing the declarion like i mentioned the problem could be solved
;) )
Though it depends on what this routine does:
testDataHandle(NewHandleClear(sizeof(testData)));
It seems to be just clearing the data...
Maybe you should post some more code... how the structure and pointers are
allocated.
And maybe a description of the routine and it's prototype ;)
So to me it seems the structures etc are a bit f*cked up ;)
If that's not the case... and you are 100% sure you know what you doing yhen
it's probably something totally else... and I should just butt out... lol.
Bye,
Skybuck.
More information about the fpc-pascal
mailing list