Solved

far pointer

Posted on 2008-06-10
11
338 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
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
Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 

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

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilationā€¦
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called eeā€¦
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

770 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