Displacement between two pointer variable..
Select messages from
# through # FAQ
[/[Print]\]

MVSFORUMS.com -> Application Programming

#1: Displacement between two pointer variable.. Author: meeran PostPosted: Thu Feb 06, 2003 11:37 am
    —
I have two pointer varible say A and B.How can i get the displacement between the address using cobol program?

#2:  Author: kolusuLocation: San Jose PostPosted: Thu Feb 06, 2003 12:53 pm
    —
meeran,

Techincally you can't perform arithmetic on pointers.ie. you cannot add or subtract with pointers.However you can REDEFINE it as a numeric type, making a correct but non-portable assumption about the physical representation of a pointer.

Hope this helps...

cheers

kolusu

#3:  Author: zatlas PostPosted: Thu Feb 06, 2003 1:07 pm
    —
Hi
Many years ago when I've learned C, my teacher told me something that was a revelation for me. He said "a pointer is the same as an index (or subscript)". Relate to the whole entity that these pointers pointing to a s big array of one character elements, use idices and voila, the solution is easy.
It works, I've used this technique myself and could point you to examples.
ZA

#4:  Author: CaptBillLocation: Pasadena, California, USA PostPosted: Thu Feb 06, 2003 2:51 pm
    —
Can't speak for C but an index and subscript are very different things in COBOL.

An index is a displacement value while a subscript is an occurrance number.

For example if you have a table of month names, each occupying 9 bytes and you elect to use the fifth entry in the table, then the index would have the value of 36. The subscript would have the value of 5.

This is true for VISION: Results (DYL-280) and other higher level languages I am familiar with.

#5:  Author: semigeezerLocation: Atlantis PostPosted: Thu Feb 06, 2003 3:08 pm
    —
Preface: I don't know COBOL (thank goodness)...

I think what he means is that a pointer is just an 'index' into an implied array of characters starting at location 0. I have no idea how COBOL handles pointers, but at the assembly level it is dangerous to do arithmatic on them directly because some methods of getting pointers include the high order bit from the PSW so that (for 31 bit addresses) the number is treated as a negative number when used in arithmetic operations or (for 24 bit addresses) the number may contain garbage in the 1st byte. Usually XORing the 1st bit off is a good thing to do.

#6:  Author: DaveyCLocation: Perth, Western Australia PostPosted: Thu Feb 06, 2003 9:47 pm
    —
Good point by semigeezer, I wouldn't have thought of that. As pointer arithmetic is not supported by COBOL without a REDEFINEs workaround I would bear that in mind.

Quote:
Can't speak for C but an index and subscript are very different things in COBOL


Hmm, another COBOL idiosyncracy. In C, any weakly defined type automatically decays to a pointer. That means that an array is just a pointer and can be processed by subscripting or by pointer arithmetic. This is especially useful when allocating dynamic arrays. C programmers (me included) are often guilty of overdoing the pointer arithmetic. Subscripting is easier to understand and the optimizer will always convert subscripting into pointer arithmetic.



MVSFORUMS.com -> Application Programming


output generated using printer-friendly topic mod. All times are GMT - 5 Hours

Page 1 of 1

Powered by phpBB © 2001, 2005 phpBB Group