MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Displacement between two pointer variable..

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming
View previous topic :: View next topic  
Author Message
meeran
Beginner


Joined: 23 Dec 2002
Posts: 7
Topics: 3

PostPosted: Thu Feb 06, 2003 11:37 am    Post subject: Displacement between two pointer variable.. Reply with quote

I have two pointer varible say A and B.How can i get the displacement between the address using cobol program?
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12376
Topics: 75
Location: San Jose

PostPosted: Thu Feb 06, 2003 12:53 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
zatlas
Beginner


Joined: 17 Dec 2002
Posts: 43
Topics: 4

PostPosted: Thu Feb 06, 2003 1:07 pm    Post subject: Reply with quote

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
View user's profile Send private message
CaptBill
Beginner


Joined: 02 Dec 2002
Posts: 100
Topics: 2
Location: Pasadena, California, USA

PostPosted: Thu Feb 06, 2003 2:51 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
semigeezer
Supermod


Joined: 03 Jan 2003
Posts: 1014
Topics: 13
Location: Atlantis

PostPosted: Thu Feb 06, 2003 3:08 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
DaveyC
Moderator


Joined: 02 Dec 2002
Posts: 151
Topics: 3
Location: Perth, Western Australia

PostPosted: Thu Feb 06, 2003 9:47 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group