Archived

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

Fender148

Whats a far pointer?

Recommended Posts

I think that far and near pointers were only for 16 bit programming. A near pointer was a 16 bit pointer, and a far pointer was a 32 bit one (it could point into FAR memory). This could, I have heard, come back when we are still doing 32 bit programming when there is 64 bit level memory available.

Dont take my word for it, I''ve never used far pointers Just going off what I''ve heard.

Share this post


Link to post
Share on other sites
Far pointers are relicts of the ancient 16 bit days. The reason for their use was that the memory was divided in 64K blocks and
to access something outside your current block you used far pointers. That made coding, especially in assembler, a big mess.
Forget that, thing like this will never come back even for a new
64 bit architecture. The industry would never accept that.

cu

Peter

Share this post


Link to post
Share on other sites
A far pointer isn''t just something left over from the 16 bit days...

It refers to a full pointer definition, in segment:offset notation.
In 16 bit a full pointer is 32 bits wide (SSSS:XXXX)
In 32 bit a full pointer should be 48 bits wide (SSSS:XXXXXXXX)

Where the ''SSSS'' represents the segment/selector, and ''XXXX'' represents the offset. The 48 bit pointer model can be found in use in compilers like DJGPP.

A near pointer is simply the offset portion of the far address; the base of which is set by the curent running environment (which assumes a constant segment/selector part). So in protected memory layouts like in Windows near pointers are all you get...

The importance of differentiating between the two type comes at a lower level (Driver/OS) where you need to address across the full range of memory. Though generally it''s not something you should worry about; use near pointers...

- And when we move to 64 bit I think selector:offset notation for far pointers will be just as valid as it is for 32 bit apps..

Jans.








-----------------
Janucybermetaltvgothmogbunny

Share this post


Link to post
Share on other sites
quote:
Original post by Jansic

A far pointer isn''t just something left over from the 16 bit days...

From my point of view is indeed a relict, because a few years ago poor windows C programmers had really to think in these terms and nowadays they dont''t have to anymore. And that''s why it is a relict to me. I can remember that very well and I am really glad that I dont must think in terms of memory models
(small, tiny, big, huge, ...) and NEAR FAR PASCAL SOMETHING. Instead I can write normal ANSI C / C++. That''s was my intention to say "relict".


It refers to a full pointer definition, in segment:offset notation.
In 16 bit a full pointer is 32 bits wide (SSSS:XXXX)
In 32 bit a full pointer should be 48 bits wide (SSSS:XXXXXXXX)

Where the ''SSSS'' represents the segment/selector, and ''XXXX'' represents the offset. The 48 bit pointer model can be found in use in compilers like DJGPP.

A near pointer is simply the offset portion of the far address; the base of which is set by the curent running environment (which assumes a constant segment/selector part). So in protected memory layouts like in Windows near pointers are all you get...

Since I used assembler a lot, i am also aware of these facts.
But to me it did not make to much sense to explain some facts to
someone who might does not know what segments or a global descriptor table is.



The importance of differentiating between the two type comes at a lower level (Driver/OS) where you need to address across the full range of memory. Though generally it''s not something you should worry about; use near pointers...

Why should I mess up my code with plattformdependent modifiers like NEAR or FAR ?????
I tend to write my stuff plattformindependent.



-----------------
Janucybermetaltvgothmogbunny


cu

Peter

Share this post


Link to post
Share on other sites
Yes, from an application programmers point of view the difference between near & far in today''s world of protected memory and linear addressing is an irrelevant and ''legacy'' concept. To low level and system programmers however the concept is still very real...

All I did was offer an explanation and a reason; as was requested...

Jans.


-----------------
Janucybermetaltvgothmogbunny

Share this post


Link to post
Share on other sites
Missed a bit -

quote:

Why should I mess up my code with plattformdependent modifiers like NEAR or FAR ?????
I tend to write my stuff plattformindependent.



Actually, careful use of #define FAR xxx and #define NEAR xxx, will _aid_ you in creating cross platform code... I program embedded systems and have a single piece of code which runs on two different architecture PIC chips; one of which uses 16:16 bit paged memory, one of which uses 32 bit flat memory; Which is only made possible by careful use of FAR & NEAR...

Anyway, I digress...

Jans.

-----------------
Janucybermetaltvgothmogbunny

Share this post


Link to post
Share on other sites