View previous topic :: View next topic |
Author |
Message |
meeran Beginner
Joined: 23 Dec 2002 Posts: 7 Topics: 3
|
Posted: Thu Feb 06, 2003 11:37 am Post subject: Displacement between two pointer variable.. |
|
|
I have two pointer varible say A and B.How can i get the displacement between the address using cobol program? |
|
Back to top |
|
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12376 Topics: 75 Location: San Jose
|
Posted: Thu Feb 06, 2003 12:53 pm Post subject: |
|
|
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 |
|
Back to top |
|
|
zatlas Beginner
Joined: 17 Dec 2002 Posts: 43 Topics: 4
|
Posted: Thu Feb 06, 2003 1:07 pm Post subject: |
|
|
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 |
|
Back to top |
|
|
CaptBill Beginner
Joined: 02 Dec 2002 Posts: 100 Topics: 2 Location: Pasadena, California, USA
|
Posted: Thu Feb 06, 2003 2:51 pm Post subject: |
|
|
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. |
|
Back to top |
|
|
semigeezer Supermod
Joined: 03 Jan 2003 Posts: 1014 Topics: 13 Location: Atlantis
|
Posted: Thu Feb 06, 2003 3:08 pm Post subject: |
|
|
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. |
|
Back to top |
|
|
DaveyC Moderator
Joined: 02 Dec 2002 Posts: 151 Topics: 3 Location: Perth, Western Australia
|
Posted: Thu Feb 06, 2003 9:47 pm Post subject: |
|
|
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. _________________ Dave Crayford |
|
Back to top |
|
|
|
|