Solved

far pointer

Posted on 2008-06-10
11
341 Views
Last Modified: 2013-12-14
I have a code which is as follows

typedef struct {
    int offset
    int handle
}objectptr;

typedef objectptr far   *objptr;

I would like to know purpose of far keyword here?

If necessary i can attach code snippet

Regards
Sham




 

0
Comment
Question by:sham_ibmgs
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
11 Comments
 
LVL 9

Expert Comment

by:Rob Siklos
ID: 21752299
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 21752434
far pointers were used in legacy code to access memory locations outside the current segment (16 bit segment + 16 bit offset = 32 bit pointer while pointers at that time used to be 16 bits - the days of 16 bit systems and DOS). We used to have near far and huge pointers.
I would imagine that code would be using a farmalloc to allocate memory for objptr.
Here are details of architecture and segments that would give you the rationale
http://www.experts-exchange.com/Programming/Languages/CPP/Q_20106123.html
http://answers.yahoo.com/question/index?qid=20070611213330AAewopS
0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 21753197
The 'far' keyword defaults to nothing in any 32-bit development. You simply should omit it beside you would develop 16bit applications.
0
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 

Author Comment

by:sham_ibmgs
ID: 21757035
@itsmeand: How 'far'  keyword is relevant to 16 bit applications?

 
0
 

Author Comment

by:sham_ibmgs
ID: 21757072
@itmeand: How the following structure[offset/handle] is used in 16 bit and 32 bit scenario?
typedef struct {
    int offset
    int handle
}objectptr;

typedef objectptr far   *objptr;

Regards
Sham
0
 

Author Comment

by:sham_ibmgs
ID: 21757108
@itmeaned: I have read the comment in your attached link, i could not understand the following point:

The Segment part 'addresses' 16 byte blocks, the Offset specifies an offset from the start of this 16 byte block (note this offset can be from 0 to 64K, leading to the uncomfortable situation where two different Segment/Offset pairs adress the same memory).

Can u explain, how pairs address to same memory?

Regards
Sham
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 21757158
I guess you are mixing my comments with those of itsmeandnobodyelse but I would try to give some clarifications anyway

16 bit application - 16 bit pointer ... you cannot address more than 64 K. Address space however is 20 bits, so you cannot address entire memory using 16 bit pointers .... This is where far pointers enter the scene. Given the segmented memory model, capability to address memory in another segment allows you to address entire memory - 16 bit segment and 16 bit offset

far keyword does not affect how the struct would be used. It simply tells that memory is located in a different segment. Members would still be accessed using -> operator

Now that you have 32 (16+16) bit addressing capability and only 20 bit address space, an overlap is possible if your segments are not 64K in size.
e.g.
Seg1 0-16K
Seg2 16K-32K
A far pointer to Seg1 and offset 16K+1 is referencing the same memory as a far pointer to Seg2 and offset1

Cheers!
sunnycoder
0
 

Author Comment

by:sham_ibmgs
ID: 21757614
@sunny: In your latest post, i did not understand this point "Now that you have 32 (16+16) bit addressing capability and only 20 bit address space, an overlap is possible if your segments are not 64K in size" what do u mean (16+16) here?

Anyways, i would like to know another point: In 16 bit architecture[ex: 8086], segmented memory model is used, where each segment is of size 2^16 bytes(64K) and 2^4(16) different segments. What about 32 bit architecture, does it have segmented memory model or linear(consecutive) address model?

Regards
Sham
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 21757632
The architecture that was reference in the overlap post had 20 bit addresses ... so 2^20 memory locations to address. A 32 bit far pointer lets you address 2^32 memory locations.
16+16 means 16 bits for offset and 16 for identifying the segment
32 bit architecture has segments like code segment, data segment but these are constructed based on needs of a program rather than being dictated by the physical limitations. These segments have no relation with the legacy memory models. You dont need far and huge pointers in this case.
0
 

Author Comment

by:sham_ibmgs
ID: 21757678
Following code is currently running in 32 bit processors/ Windows, am unable to understand, why far pointers and getdataaddres() is used? Cant we use simple pointers[int *] rather than POBJPTR as shown here?
Please help me in understanding:
1)  the reason for using type objectptr rather than simple int
2) Purpose of using far pointer

typedef struct {
    int offset
    int handle
}objectptr;
typedef objectptr far   *POBJPTR;

ERROR_CODE FAR  func (phWnd, pFileName, pDummy)
POBJPTR     phWnd;
POBJPTR     pFileName;
POBJPTR     pDummy;
   {
   char        szFileName [PATHNAME_LENGTH + 1];
   POBJPTR     pList;
   POBJPTR     pSize;
  SetFunctionName (TLBSave);
 /* save database file name */
   strcpy (szFileName, GRFGetDataAddress (pFileName));
.
.
}


VOID FAR* EXPORT GRFGetDataAddress (pObject)
POBJPTR     pObject;
   {
   LPCOPIEDHEADER lpMemBlock;
   UINT           uHandle;
   SetFunctionName (GRFGetDataAddress);
  /* check object pointer (and set variable uHandle) */
   CHECKOBJPTRFORADDRESS (pObject, uHandle, NULL);
  GETREALADDRESS (pObject, lpMemBlock, FALSE, NULL);
/* set pointer in return buffer */
   return ((VOID FAR*) ((LPSTR) lpMemBlock + sizeof (OBJECTHDR)));
}

Regards
Sham


0
 
LVL 45

Accepted Solution

by:
sunnycoder earned 100 total points
ID: 21757928
This looks like very old code ... even the syntax used is old. You cant replace objectptr far * with an int * but you can do away with the far keyword and use objectptr * only.
Far pointers are not required in this environment ... However, unless there is a compelling reason to do so, I would not recommend editing working code.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

632 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question