home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The C Users' Group Library 1994 August
/
wc-cdrom-cusersgrouplibrary-1994-08.iso
/
listings
/
v_01_03
/
1n03009a
< prev
next >
Wrap
Text File
|
1990-07-03
|
2KB
|
66 lines
Listing 3
{*
* Returns a 4-digit hex string representing the
* value of (unsigned integer) word w.
*}
function hexstr(w : word) : string;
var
s : array [1 .. 4] of char;
d, i : integer;
begin
for i := 4 downto 1 do
begin
d := w mod 16;
if d < 10 then
d := d + ord('0')
else
d := d - 10 + ord('A');
s[i] := chr(d);
w := w div 16;
end;
hexstr := s;
end;
{*
* Returns a string representing pointer p in the form
* SSSS:OOOO, where SSSS is the 4-digit hex representa-
* tion of the segment portion of p, and OOOO is the
* 4-digit hex representation of the offset portion of
* p.
*}
function ptrstr(p : pointer) : string;
type
pc = ^char;
begin
ptrstr :=
hexstr(seg(pc(p)^)) + ':' +
hexstr(ofs(pc(p)^));
end;
var
p1, p2, p3, p4 : ^longint;
begin
new(p1);
p1^ := 1;
writeln('p1 = ', ptrstr(p1), ', p1^ = ', p1^);
new(p2);
p2^ := 2;
writeln('p2 = ', ptrstr(p2), ', p2^ = ', p2^);
new(p3);
p3^ := 3;
writeln('p3 = ', ptrstr(p3), ', p3^ = ', p3^);
dispose(p2);
writeln('p2 = ', ptrstr(p2), ', p2^ = ', p2^);
new(p4);
p4^ := 4;
writeln('p4 = ', ptrstr(p4), ', p4^ = ', p4^);
writeln('p2 = ', ptrstr(p2), ', p2^ = ', p2^);
p2^ := -2;
writeln('p2 = ', ptrstr(p2), ', p2^ = ', p2^);
writeln('p4 = ', ptrstr(p4), ', p4^ = ', p4^);
end.