Printing of Pointer Type

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

Printing of Pointer Type

leledumbo
Administrator
Currently, the only way to print Pointer is to use SysUtils.Format or by typecasting it to PtrUInt first. Why not let it possible to print it directly? Any good reason for not allowing users to do it?
Reply | Threaded
Open this post in threaded view
|

Re: Printing of Pointer Type

Jonas Maebe-2

On 17 Jul 2008, at 07:38, leledumbo wrote:

> Currently, the only way to print Pointer is to use SysUtils.Format  
> or by
> typecasting it to PtrUInt first. Why not let it possible to print it
> directly? Any good reason for not allowing users to do it?

Because there are easy ways around it (as you mention) and the work to  
implement and maintain this would probably outweigh the usefulness.


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

Re: Printing of Pointer Type

leledumbo
Administrator
Jonas Maebe-2 wrote
Because there are easy ways around it (as you mention) and the work to  
implement and maintain this would probably outweigh the usefulness.
Yes, it's easy but uncomfortable and needs more typing.
Reply | Threaded
Open this post in threaded view
|

Re: Printing of Pointer Type

Vinzent Höfler
leledumbo <[hidden email]>
>
> Jonas Maebe-2 wrote:
> >
> > Because there are easy ways around it (as you mention) and the work to  
> > implement and maintain this would probably outweigh the usefulness.
> >
> Yes, it's easy but uncomfortable and needs more typing.

Well, sure, but printing pointer values in most cases is a pure debugging aid and nothing really useful.


Vinzent.
--
Psssst! Schon vom neuen GMX MultiMessenger gehört?
Der kann`s mit allen: http://www.gmx.net/de/go/multimessenger
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Printing of Pointer Type

Peter Vreman
In reply to this post by leledumbo
>> Because there are easy ways around it (as you mention) and the work to
>> implement and maintain this would probably outweigh the usefulness.
>>
> Yes, it's easy but uncomfortable and needs more typing.

You can use hexstr() to convert the pointer to a hexadeciaml number:

var p: pointer;
begin
  p:=@p;
  writeln(hexstr(p));
end.


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

Re: Printing of Pointer Type

Mattias Gaertner
In reply to this post by Vinzent Höfler
On Thu, 17 Jul 2008 10:45:22 +0200
"Vinzent Höfler" <[hidden email]> wrote:

> leledumbo <[hidden email]>
> >
> > Jonas Maebe-2 wrote:
> > >
> > > Because there are easy ways around it (as you mention) and the
> > > work to implement and maintain this would probably outweigh the
> > > usefulness.
> > >
> > Yes, it's easy but uncomfortable and needs more typing.
>
> Well, sure, but printing pointer values in most cases is a pure
> debugging aid and nothing really useful.

Well. Since the biggest time of programming is spent on debugging I
guess, there is more need for a PtrToStr than for FloatToStr.

lcl users can simply use dbgs().

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

Re: Printing of Pointer Type

Johann Glaser
Hi!

Am Donnerstag, den 17.07.2008, 21:52 +0200 schrieb Mattias Gaertner:

> On Thu, 17 Jul 2008 10:45:22 +0200
> "Vinzent Höfler" <[hidden email]> wrote:
>
> > leledumbo <[hidden email]>
> > >
> > > Jonas Maebe-2 wrote:
> > > >
> > > > Because there are easy ways around it (as you mention) and the
> > > > work to implement and maintain this would probably outweigh the
> > > > usefulness.
> > > >
> > > Yes, it's easy but uncomfortable and needs more typing.
> >
> > Well, sure, but printing pointer values in most cases is a pure
> > debugging aid and nothing really useful.
>
> Well. Since the biggest time of programming is spent on debugging I
> guess, there is more need for a PtrToStr than for FloatToStr.

I suggest to extend Write and WriteLn, that for Pointer typed parameters
those are printed in hex, e.g.

Var Edit : TEdit;
Begin
  Edit := TEdit.Create;
  WriteLn('Edit = ',Pointer(Edit));
End

then prints to the screen

  Edit = $B0283958

Would be very handy for debugging, similar like C++'s
  cout << "Edit = " << (void*)Edit << endl;
(okok, streams are ugly syntax at least, but the overloaded operator for
untyped (void) pointers comes in handy instead of FreePascal's
IntToHex(PtrUInt(Edit),8)

Bye
  Hansi


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

Re: Printing of Pointer Type

Vinzent Höfler
In reply to this post by Mattias Gaertner
Mattias Gaertner wrote:

> On Thu, 17 Jul 2008 10:45:22 +0200
> "Vinzent Höfler" <[hidden email]> wrote:
>
>> leledumbo <[hidden email]>
>>> Jonas Maebe-2 wrote:
>>>> Because there are easy ways around it (as you mention) and the
>>>> work to implement and maintain this would probably outweigh the
>>>> usefulness.
>>>>
>>> Yes, it's easy but uncomfortable and needs more typing.
>> Well, sure, but printing pointer values in most cases is a pure
>> debugging aid and nothing really useful.
>
> Well. Since the biggest time of programming is spent on debugging I
> guess, there is more need for a PtrToStr than for FloatToStr.

My mistake. As I spend most of my time designing the things first, so
that debugging (especially at such a level) is reduced to a minimum, I
might not have noticed yet that printing pointer values actually adds
value to a delivered application.

Honestly, in the rare cases where I really need to do such things, the
amount of typing work to add the typecast is negligible.


Vinzent.

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

Re: Printing of Pointer Type

Marco van de Voort
In reply to this post by Jonas Maebe-2
> On 17 Jul 2008, at 07:38, leledumbo wrote:
>
> > Currently, the only way to print Pointer is to use SysUtils.Format  
> > or by
> > typecasting it to PtrUInt first. Why not let it possible to print it
> > directly? Any good reason for not allowing users to do it?
>
> Because there are easy ways around it (as you mention) and the work to  
> implement and maintain this would probably outweigh the usefulness.

It might also interfere with existing features like writeln(pchar); ?
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal