Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

far pointer

Posted on 2008-06-10
11
Medium Priority
?
342 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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 400 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.

730 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