What is a far pointer? where we use it?

The only place I have come across far pointers in far pointers is as an extension in WIN16 C compilers.

16 bit Windows (WIN16, Windows 3.11 and earlier) had 16 bit addressing, which allowed you to access all of your 64kbyte memory segment, the pointer was the offset in the segment and was also called a near pointer although the near keyword was not required as it was implied by default.

However you could have other segments and to access these other segments you need a pointer that holds the segment number and the offset. The far pointer was the implementation of this, twice as large as a near pointer it held a 16 bit segment number as well as the 16 bit offset in the segment.

With the advent of WIN32 and a flat memory model the need for far pointers disappeared as you had 32bit pointers that could address the whole of the memory space for a process.

On older Windows (3.1 type), you need them, because it used the old 16 bit addressing memory mode.

With newer Windows, you will have to remove the far designation, or you'll get an error, even if you're using an older 16 bit, version of a compiler.

I use a very old version of Turbo C, which is 16 bit, in Windows XP. The far word must be removed or it crashes the program. (Yes, it will still compile, but it won't run).

In 32 bit Windows compiles far is #defined to nothing #define far (line 91 of WinDef.h.

On old 16bit compilers you will need to keep the far keyword in place as they will still be using the segmented memory model of 16bit windows. WIN32 systems have a WIN16 emulator (or thunk).

Note it appears that WIN64 does not have a WIN16 sub-system and you can not run WIN16 programs on WIN64 systems.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.