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?
Mailing lists / fpc-pascal / 2008-07
Printing of Pointer Type
9 messages · 7 people · –
- Lleledumbo 2
- VVinzent Höfler 2
- JJohann Glaser 1
- JJonas Maebe 1
- MMarco van de Voort 1
- MMattias Gaertner 1
- +1 more
Reply by email Subscribe to this list Your subscription
Read-only archive. Use j and k to move between messages.
leledumbo wroteCurrently, 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
Jonas Maebe-2 wroteBecause 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.
leledumbo
Show quoted text 7 lines
Well, sure, but printing pointer values in most cases is a pure debugging aid and nothing really useful.
Vinzent.
> 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
;
writeln(hexstr(p));
end.leledumbo Well, sure, but printing pointer values in most cases is a pure debugging aid…
Show quoted text 12 lines
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
Hi!
Mattias Gaertner wrote 18 lines
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));
Endthen 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
On Thu, 17 Jul 2008 10:45:22 +0200 Well. Since the biggest time of programming is spent…
Mattias Gaertner wrote 15 lines
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.
Because there are easy ways around it (as you mention) and the work to implement and…
Show quoted text 9 lines
It might also interfere with existing features like writeln(pchar); ?
