• Advertisement

Archived

This topic is now archived and is closed to further replies.

FAR and NEAR pointers?

This topic is 5372 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I have been wondering for quite some time what all those FAR and NEAR pointers are all about when programming WIN32? Why do they exist at all? Thanks for taking your time to explain this concept to me!

Share this post


Link to post
Share on other sites
Advertisement
Back in the 16 bit days, you had segments. Each segment could address 64K of data. A near pointer was for referencing data in the default segment, and a far pointer was for referencing data in another segment. NEAR was a 16 bit offset, while FAR was a 16 bit offset and a 16 bit segment identifier.

In Win32 you have a flat 32 bit address space. Everything can be referenced with a 32 bit near pointer. But now instead of segments we have selectors. Generally you don''t need to worry about them at all, but the OS uses different selectors to refer to memory of different processes, or memory specific to the OS. A far pointer would be a 48 bit pointer including a selector and an offset.

At least, that''s how a 32 bit assembler would see things. These days C compilers tend to ignore the keywords "near" and "far" and just give you a 32 bit near pointer. There may be some way to get MSVC to use a 48-bit far pointer, but as I''ve never needed such a thing, I have no idea how to make one, or if it''s even possible.

So, in short, they''re a throw back to Intel''s early architecture. Don''t worry about them.

Share this post


Link to post
Share on other sites
Thanks for the great explanation! It makes me feel so much better now that I know what they are and where they origin from!

Share this post


Link to post
Share on other sites

  • Advertisement