"combined" pointers or "linear" pointers ??? >D
From: Skybuck Flying (nospam_at_hotmail.com)
Date: 04/02/04
- Next message: Rob Kennedy: "Re: dynamic array, access violation example."
- Previous message: Rob Kennedy: "Re: Dynamic Array vs Pointer"
- In reply to: Skybuck Flying: "Re: 20 bit addressess in turbo pascal/msdos 6.22"
- Next in thread: Skybuck Flying: "Re: "combined" pointers or "linear" pointers ??? >D"
- Reply: Skybuck Flying: "Re: "combined" pointers or "linear" pointers ??? >D"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 2 Apr 2004 10:09:42 +0200
Ok now I am on a quest to find out the truth lol :)
I thought: "Oh that will be simple, I'll just write a test program and test
it in turbo pascal, like I normally do (write test programs to find out how
stuff works lol)"
Well it's not as easy as it seems.
Here is the test program I wrote in turbo pascal 7 for a pentium 166 on ms
dos 6.22 (with crt fix applied).
The comments contain the idea of the test, turbo pascal's pchar operator
limitations and some results.
It also explains what I call a "combined" pointer ( segment:offset ) and a
"linear" pointer ( which any programmer should understand :D )
I am trying to find out if turbo pascal 7's pointer type is a "combined" or
"linear" pointer type.
I am not yet sure which one it is =D
Any "test" ideas are further information are welcome ! =D
*** tp7 code starts here ***
program pointer;
{
Program to test how pointers work in turbo pascal 7/ms dos 6.22 (real
mode)
Version 0.01 created on 2 april 2004 by Skybuck Flying
Let's find out how pointers work (32 bit variables) in turbo pascal 7.
1. Do they point to "combined" addressess like segment:offset
or
2. Do they point to "linear" addressess like offsets
:)
We do this with pointer arithmetic... we are going to increase the pointer
with 1 in a loop.
Then we will examine the high 16 bits and low 16 bits :)
We will compare the pointer value with the lineair value. If it is the
same
value this means pointers are lineair. If it is not this means
pointers are "combined" :)
Hmm it seems this theory might not fly =D
Since the turbo pascal help says that Pchar's operator's '-' and '+'
only work on the offset part of the pointer ?
Well we'll try it anyway and see what happens :D
The example shows a difference at:
I = 65536, P = 0 ?
Pretty strange... the rest is the same ?
( Maybe it is because the pointer's offset wrapped, this would indicate
a "combined" pointer... or maybe only the offset can be incremented like
the help says ;) )
I still want to know if it is combined or lineair hmmm...
( Well at this point we can't use pointer arithmetic above 64 KB offsets
that means we would have to "normalize" the pointers to prevent offset
wrapping (since the segment address is probably not correctly incremented
when a wrap occurs) )
Well at the moment I am out of ideas... =D
}
uses
crt;
var
p : pointer;
i : longint;
start_value : longint;
stop_value : longint;
difference_detected : boolean;
begin
clrscr; { disable this line if crt fix has not been applied and using a
fast processor }
{ let's use 'control' variables to control the loop's range }
{ start value }
start_value := 0;
{ stop value }
stop_value := 100000; { loop beyond 64 KB }
{ let's use a flag to indicate when a difference as been found }
difference_detected := false;
{ initialize pointer to zero }
longint(p) := start_value;
{ loop I and pointer }
for i:=start_value to stop_value do
begin
{ compare pointer value to linear value }
if longint(p) <> i then
begin
{ let's only print the first time when difference detected was still
false }
if not difference_detected then
begin
{ !! different !!, non lineair ! }
writeln('difference detected at: ');
writeln('i: ', i, ' p: ', longint(p) );
end;
difference_detected := true;
end;
{ now increase pointer :) }
Pchar(p) := Pchar(p) + 1;
end;
end.
Skybuck.
- Next message: Rob Kennedy: "Re: dynamic array, access violation example."
- Previous message: Rob Kennedy: "Re: Dynamic Array vs Pointer"
- In reply to: Skybuck Flying: "Re: 20 bit addressess in turbo pascal/msdos 6.22"
- Next in thread: Skybuck Flying: "Re: "combined" pointers or "linear" pointers ??? >D"
- Reply: Skybuck Flying: "Re: "combined" pointers or "linear" pointers ??? >D"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|