Recent

Author Topic: [Solved] pointers  (Read 1977 times)

Ten_Mile_Hike

  • Jr. Member
  • **
  • Posts: 87
[Solved] pointers
« on: May 20, 2024, 12:13:37 am »
I know the BASICS of pointers, but I'm just playing around ---and wondered;
if the value of memory location of A below is 341576016 how can I display that in pascal?
I've tried ABSOLUTE and did get a  7 digit value back, but I don't know if that is valid.
If not in pascal, how about inline ASM?

AGAIN...I'm just goofing around. Not trying to program anything

Thanks


Code: Pascal  [Select][+][-]
  1. var
  2.   A:Integer;
  3.   A_Ptr:PInteger;
  4. begin
  5.   A:=77;
  6.   A_PTR:=@A;    
  7.  

« Last Edit: May 22, 2024, 06:52:08 am by Ten_Mile_Hike »
When any government, or any church for that matter, undertakes to say to its subjects, This you may not read, this you
must not see, this you are forbidden to know, the end result is tyranny and oppression no matter how holy the motives.

Robert A. Heinlein

jamie

  • Hero Member
  • *****
  • Posts: 6735
Re: pointers
« Reply #1 on: May 20, 2024, 12:26:59 am »
Writeln(IntToStr(A_Ptr^));
The only true wisdom is knowing you know nothing

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 10553
  • Debugger - SynEdit - and more
    • wiki
Re: pointers
« Reply #2 on: May 20, 2024, 01:46:35 pm »
The actual address stored in the pointer:

Code: Pascal  [Select][+][-]
  1. writeln(IntToStr(PtrUInt(A_Ptr)));

Or "IntToHex" if you prefer.

PtrUInt will be QWord or Cardinal (or ...) depending on what bitness you compile for. So you can always use this to cast the pointer into a number.

TRon

  • Hero Member
  • *****
  • Posts: 3647
Re: pointers
« Reply #3 on: May 20, 2024, 01:53:24 pm »
In addition, and in case not wanting to rely on sysutils:
Code: Pascal  [Select][+][-]
  1.   WriteLn(HexStr(A_Ptr));
  2.  
This tagline is powered by AI (AI advertisement: Free Pascal the only programming language that matters)

gidesa

  • Full Member
  • ***
  • Posts: 145
Re: pointers
« Reply #4 on: May 20, 2024, 02:21:54 pm »
There is also format() with P type argument,
see: https://www.freepascal.org/docs-html/rtl/sysutils/format.html

Code: Pascal  [Select][+][-]
  1. uses SysUtils;
  2. .............
  3. Writeln(Format('%P',[A_ptr]));
  4.  
« Last Edit: May 20, 2024, 02:36:58 pm by gidesa »

Thaddy

  • Hero Member
  • *****
  • Posts: 16194
  • Censorship about opinions does not belong here.
Re: pointers
« Reply #5 on: May 20, 2024, 03:19:01 pm »
Format is overkill:
Code: Pascal  [Select][+][-]
  1. var
  2.   b:PtrUint = 12345;
  3. begin
  4.   writeln(b);            // value
  5.   writeln(PtrUint(@b));  // address
  6. end.
If I smell bad code it usually is bad code and that includes my own code.

Ten_Mile_Hike

  • Jr. Member
  • **
  • Posts: 87
Re: [Solved] pointers
« Reply #6 on: May 22, 2024, 06:53:39 am »
Thank you everyone for your responses.
I greatly appreciate it.
When any government, or any church for that matter, undertakes to say to its subjects, This you may not read, this you
must not see, this you are forbidden to know, the end result is tyranny and oppression no matter how holy the motives.

Robert A. Heinlein

 

TinyPortal © 2005-2018