comparing pointers

   How to compare two pointers?


procedure checksum(...);
x: ^word;
y: ^word;
sum: Longint;
  x := @first_procedure;
  y := @next_procedure;
  sum := 0;

    sum := sum + x^;
  until x > y


    Compiler reports error after "until".
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Type cast your word pointers as normal pointers, e.g.

until pointer(x)>pointer(y)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
biberAuthor Commented:
Well, it seems that is not solution :(

Delphi says "Operand types do not match operator"

Any other idea?
Please let me know what you are doing here ...

What is first_procedure and next_procedure ? Are they word variables that you are trying to compare ? Why don't you compare the values themselves ?

If you explain a bit more I can try and find a solution for you.

PS It is possible to compare pointers. If this is necesarry I will go and have a look what Delphi wants. I suspect there is another and better way to do this ;^)

Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

biberAuthor Commented:
Sorry, I should put some comments.

Procedure "Checksum" should calculate sum of memory locations
between two procedures (I called them "first_procedure" and

Delphi generates "Operand types do not match operator" error
no matter if I define "x" and "y" as "x, y: ^word" or
"x, y: pointer"

>> PS It is possible to compare pointers. If this is necesarry I >> will go and have a look what Delphi wants. I suspect there is >> another and better way to do this ;^)

   Please do.

How about if you compare until x=y? That would cover everything between the two procedures, IF they are consecutively in memory. (If next_proc is before first_proc, the program will of course never end) OR, if you really want to check x>y, you can typecase each of them to a longint. (I actually didn't think with my original answer what you were doing, I know pointer comparison wrt > and < is not allowed, but = is allowed)
biberAuthor Commented:
> How about if you compare until x=y?

    Yes, that works, but Inc(x) (x is ^word) inrements x for one word (two bytes). What if @first_procedure is odd and @next_procedure is even? Loop will never end. Althought I am not sure about addresses, if they are always even.

     Anyway typecasting to longint works, and I guess that was solution.

There is another problem with procedure:
At "sum := sum + x^;"  compiler reports GPF. What could be the cause?

BTW How to "pay" you now for all this answers?
Is it the compiler that gives GPF, or when the program is run?
biberAuthor Commented:
Sorry, I made a mistake.
GPF is generated during run-time - just try example.
This is probably because the procedures are not aligned in memory. They are not forced to be and they might be movable in memory.

If you are still strugling with this I would suggest you post this as another question and maybe someone else could help you to solve it ;^)

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.