How to get rid of hint?

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

How to get rid of hint?

Mattias Gaertner

I want to compute the offset/difference between two pointers. But I didn't
found a way to do that without compiler hints.

unit1.pas(42,6) Hint: Conversion between ordinals and pointers is not
portable

var
  p1, p2: pointer;
  i: PtrInt;
begin
  ...
  i:=PtrInt(p1)-PtrInt(p2);
  ...
end;

Any idea, how to get rid of the hint?

Mattias
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: How to get rid of hint?

Marco van de Voort
>   i:=PtrInt(p1)-PtrInt(p2);

i:=prtint(p1-p2);

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: How to get rid of hint?

Micha Nelissen
On Sat, 20 May 2006 22:50:17 +0200 (CEST)
[hidden email] (Marco van de Voort) wrote:

> >   i:=PtrInt(p1)-PtrInt(p2);
>
> i:=prtint(p1-p2);

Is the cast still necessary here ?

Micha
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: How to get rid of hint?

Mattias Gaertner
In reply to this post by Marco van de Voort
On Sat, 20 May 2006 22:50:17 +0200 (CEST)
[hidden email] (Marco van de Voort) wrote:

> >   i:=PtrInt(p1)-PtrInt(p2);
>
> i:=prtint(p1-p2);

Thanks.
So the trick to get convert a Pointer to an ordinal is to add/subtract
something. For example:
i:=PtrInt(p1-nil);

Is there a better trick?
What type has Pointer-Pointer?


Mattias

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: How to get rid of hint?

Florian Klaempfl
In reply to this post by Micha Nelissen
Micha Nelissen wrote:
> On Sat, 20 May 2006 22:50:17 +0200 (CEST)
> [hidden email] (Marco van de Voort) wrote:
>
>>>   i:=PtrInt(p1)-PtrInt(p2);
>> i:=prtint(p1-p2);
>
> Is the cast still necessary here ?

No.

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: How to get rid of hint?

Florian Klaempfl
In reply to this post by Mattias Gaertner
Mattias Gaertner wrote:

> On Sat, 20 May 2006 22:50:17 +0200 (CEST)
> [hidden email] (Marco van de Voort) wrote:
>
>>>   i:=PtrInt(p1)-PtrInt(p2);
>> i:=prtint(p1-p2);
>
> Thanks.
> So the trick to get convert a Pointer to an ordinal is to add/subtract
> something. For example:
> i:=PtrInt(p1-nil);
>
> Is there a better trick?

Let me ask the other way round: what do you want to achieve :)?

> What type has Pointer-Pointer?
>

PtrInt
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: How to get rid of hint?

Mattias Gaertner
On Sat, 20 May 2006 23:20:41 +0200
Florian Klaempfl <[hidden email]> wrote:

> Mattias Gaertner wrote:
> > On Sat, 20 May 2006 22:50:17 +0200 (CEST)
> > [hidden email] (Marco van de Voort) wrote:
> >
> >>>   i:=PtrInt(p1)-PtrInt(p2);
> >> i:=prtint(p1-p2);
> >
> > Thanks.
> > So the trick to get convert a Pointer to an ordinal is to add/subtract
> > something. For example:
> > i:=PtrInt(p1-nil);
> >
> > Is there a better trick?
>
> Let me ask the other way round: what do you want to achieve :)?

I have some classes, that implement quite abstract structures. Of course
pascal wants a type, so they use a base type:  Pointer.
Now I want to store PtrInt.
And the other way round.
So, I must type case from one to the other and back.
With templates or some include file tricks I could probably avoid the
problem.

 
> > What type has Pointer-Pointer?
> >
>
> PtrInt

Thanks. I thought so.


Mattias
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: How to get rid of hint?

Florian Klaempfl
Mattias Gaertner wrote:

> On Sat, 20 May 2006 23:20:41 +0200
> Florian Klaempfl <[hidden email]> wrote:
>
>> Mattias Gaertner wrote:
>>> On Sat, 20 May 2006 22:50:17 +0200 (CEST)
>>> [hidden email] (Marco van de Voort) wrote:
>>>
>>>>>   i:=PtrInt(p1)-PtrInt(p2);
>>>> i:=prtint(p1-p2);
>>> Thanks.
>>> So the trick to get convert a Pointer to an ordinal is to add/subtract
>>> something. For example:
>>> i:=PtrInt(p1-nil);
>>>
>>> Is there a better trick?
>> Let me ask the other way round: what do you want to achieve :)?
>
> I have some classes, that implement quite abstract structures. Of course
> pascal wants a type, so they use a base type:  Pointer.
> Now I want to store PtrInt.
> And the other way round.
> So, I must type case from one to the other and back.
> With templates or some include file tricks I could probably avoid the
> problem.

Wait with this till 2.2 is finish and get first lazarus 1.0 out of the
door :)
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: How to get rid of hint?

Mattias Gaertner
On Sun, 21 May 2006 18:36:08 +0200
Florian Klaempfl <[hidden email]> wrote:

> Mattias Gaertner wrote:
> > On Sat, 20 May 2006 23:20:41 +0200
> > Florian Klaempfl <[hidden email]> wrote:
> >
> >> Mattias Gaertner wrote:
> >>> On Sat, 20 May 2006 22:50:17 +0200 (CEST)
> >>> [hidden email] (Marco van de Voort) wrote:
> >>>
> >>>>>   i:=PtrInt(p1)-PtrInt(p2);
> >>>> i:=prtint(p1-p2);
> >>> Thanks.
> >>> So the trick to get convert a Pointer to an ordinal is to add/subtract
> >>> something. For example:
> >>> i:=PtrInt(p1-nil);
> >>>
> >>> Is there a better trick?
> >> Let me ask the other way round: what do you want to achieve :)?
> >
> > I have some classes, that implement quite abstract structures. Of course
> > pascal wants a type, so they use a base type:  Pointer.
> > Now I want to store PtrInt.
> > And the other way round.
> > So, I must type case from one to the other and back.
> > With templates or some include file tricks I could probably avoid the
> > problem.
>
> Wait with this till 2.2 is finish and get first lazarus 1.0 out of the
> door :)

Well, 1000 bug reports ago I estimated that only 300 todo left. Lazarus 1.0
is a hydra.


Mattias
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: How to get rid of hint?

Florian Klaempfl
Mattias Gaertner wrote:

> On Sun, 21 May 2006 18:36:08 +0200
> Florian Klaempfl <[hidden email]> wrote:
>
>> Mattias Gaertner wrote:
>>> On Sat, 20 May 2006 23:20:41 +0200
>>> Florian Klaempfl <[hidden email]> wrote:
>>>
>>>> Mattias Gaertner wrote:
>>>>> On Sat, 20 May 2006 22:50:17 +0200 (CEST)
>>>>> [hidden email] (Marco van de Voort) wrote:
>>>>>
>>>>>>>   i:=PtrInt(p1)-PtrInt(p2);
>>>>>> i:=prtint(p1-p2);
>>>>> Thanks.
>>>>> So the trick to get convert a Pointer to an ordinal is to add/subtract
>>>>> something. For example:
>>>>> i:=PtrInt(p1-nil);
>>>>>
>>>>> Is there a better trick?
>>>> Let me ask the other way round: what do you want to achieve :)?
>>> I have some classes, that implement quite abstract structures. Of course
>>> pascal wants a type, so they use a base type:  Pointer.
>>> Now I want to store PtrInt.
>>> And the other way round.
>>> So, I must type case from one to the other and back.
>>> With templates or some include file tricks I could probably avoid the
>>> problem.
>> Wait with this till 2.2 is finish and get first lazarus 1.0 out of the
>> door :)
>
> Well, 1000 bug reports ago I estimated that only 300 todo left. Lazarus 1.0
> is a hydra.

We felt the same way at pre 1.0 times with FPC ;(
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal