answersLogoWhite

0


Best Answer

It is a matter of the memory model you are using. On old or embedded systems, some memory was outside of the range of a normal pointer. If you have 4 megs of ram you need at least a 22bit pointer to see all of it. But let's say you only have a 16 bit pointer. This means you can only access the first 65K of ram. Odd as it may sound, this was a problem on old computers, and is sometimes an issue on embedded devices with limited processing power. The near and far classifications were a solution. Pointers are near by default. In my example above, the 65K of ram would be accessed with a near pointer. To get past that 16 bit limit, you need a far pointer. Thus: memory within the pointer's range is near. Memory outside of the range is far. Near pointer: char near * ptr; Far pointer: char far * ptr;
A far pointer uses both the segment and the offset address to point to a location in memory. A near pointer in contrast uses only the offset address and the default segment. The far pointer can point to any location in memory, whereas the near pointer can only point to a nearby local address.
Something that was important 20 years ago. Now you can forget it.

User Avatar

Wiki User

12y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

11y ago

It's an old pointer style that was used when memory was segmented, such as in 16-bit DOS systems. A near pointer was simply treated an offset within the current segment, and could therefore be reduced in length from the normal 2 bytes to just 1 byte, thus conserving memory. A far pointer was used when crossing segments, and required additional information to refer to the segment and the offset within the segment, which would require at least two bytes. In modern systems, memory is not segmented and can be referenced using a full-width pointer (32-bit or 64-bit), thus the concept of near or far pointers is meaningless.

This answer is:
User Avatar

User Avatar

Wiki User

8y ago

Far and near pointer is only introduced in turbo C compiler.When the pointer refers to an address in the same segment it is called near pointer, but when it refers to an address in another segment it is called far pointer.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is far and near pointer and how are they used?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What is the contents of the stack pointer after the execution of the call instruction?

On a near call, the stack pointer is 2 less than its original value. On a far call, it is 4 less.


Why far pointer is not there in Linux?

Pointer types are very specific to the compiler used and oftentimes subject to the target architecture. The concept of a near/far differentiation may not have any meaning on the memory model of your target. This has nothing to do with Linux or whatever OS you choose to use. More information should be provided with the documentation of your compiler.


Far pointer size in C plus plus?

If you are talking "far pointer", then you are probably talking about real mode in a 16 bit environment such as DOS or Windows 3.1, or in Virtual 8086 mode in Windows 95 or higher. In this mode, addressing is segmented into 65536 segments of 65536 bytes each, but each segment overlaps the next by only a 16 byte offset. This gives you addressability to 1048576 bytes. A far pointer is a 32 bit object, containing a 16 bit segment and a 16 bit offset. int __far *p; /* a far pointer called p which points to an int */


What is near far and huge pointers How many bytes are occupied by them?

Near, far, and huge pointers are different types of pointers used to reconcile the different addressing models of the Intel 8086/8088 class processors, running in a 16-bit operating system such as Windows 3.x, as well as any of the newer incarnations running in real mode or virtual 8086 mode.A near pointer can address something within one 64Kb memory segment, containing only an offset, and it takes two bytes. The segment is implied by context, and is usually the data segment, selected for the addressing model.A far pointer can address anything in the 1Mb memory1, containing both a segment and an offset, and it takes four bytes.A huge pointer is a normalised far pointer, which means its offset part is always between 00H and 0FH.In 32-bit mode a pointer can address anything in 4Gb memory, containing a flat 32-bit offset, and it takes four bytes. (In this mode segments have no significance.) It only works, however, when there is support for it, such as the WIN32 extension of Windows 3.x.---------------------------------------------------------------------------------------1In the 80286 or higher, running in protected mode, in OS/2, the segment portion of the pointer is actually a descriptor selector, so 1Mb addressibility depends on the operating system environment.far huge near pointer is an oxymoron. far points to memory outside of the normal address space. near points to memory within the normal address space, is the default, and usually is not needed. I've never seen huge before. What is the target architecture?Near, far, and huge pointers are a construct (usually) in the Win16 environment running on an 8086/8088 or later in real mode, such as Visual C/C++ 1.52. In this environment, near pointers are 16 bits, and far and huge pointers are 32 bits.


What is difference between Near structure and far structure?

We haven't used near and far addressing for well over a decade. It was common in older systems where memory was addressed by segment and offset. For instance, on a 32-bit system we might use 16-bits to address the segment and 16-bits to address the offset within that segment. If we were referring to an offset within the current segment then we'd use a 16-bit near pointer, but if we needed to refer to another segment then we'd use a 32-bit far pointer. Today we use a normalised pointers.

Related questions

When should a far pointer be used?

Never. 'near' and 'far' pointers are outdated by twenty years!


Is Far pointer necessary to create a circular linked list?

It has to be a pointer all right.Regarding 'far' and 'near': forget it, simply use 'Large' data modell (or 'Huge').


What is the contents of the stack pointer after the execution of the call instruction?

On a near call, the stack pointer is 2 less than its original value. On a far call, it is 4 less.


Why far pointer is not there in Linux?

Pointer types are very specific to the compiler used and oftentimes subject to the target architecture. The concept of a near/far differentiation may not have any meaning on the memory model of your target. This has nothing to do with Linux or whatever OS you choose to use. More information should be provided with the documentation of your compiler.


What is near pointer?

In the segmented memory model, a near pointer is a memory address that resides in the same segment as the current segment pointer. It had half the memory requirements of a far pointer (which stored the segment and offset, instead of just the offset), but was limited to 1/65536th the maximum distance of the memory that could be referenced. Since the introduction of the flat memory model, all pointers are near pointers, because segments are no longer used in the segmented model addressing. Instead, segments are used for task gates (protected memory), so no normal program would ever access a segment directly. A developer would only need to worry about "near" and "far" pointers on 386s and older processors. It should be noted that other system architectures, such as PowerPC, RISC, and so on, all do not have the concept of segmented memory, and so do not have near or far pointers at all. Instead, all pointers are of the same size and can address any memory location.


What is the use of near pointer?

*


What is the memory representation of far and near pointers in C?

In Intel 16-bit x86 architecture, memory was arranged in 64K segments. Two 16-bit words were used to address a specific memory location; 16 bits to identify the segment and 16 bits to identify the offset within that segment. A near pointer only requires 16 bits of storage because it refers to memory as an offset into the current segment whereas a far pointer requires the full 32 bits. However, near pointers are only useful in tiny, small or medium memory models. In all other models, pointers are far by default and introducing an explicit near pointer would be disastrous. In 32-bit architecture, there is only one segment of 4GB starting at address 0x0, therefore the concept of near and far pointers is not an issue.


Far pointer size in C plus plus?

If you are talking "far pointer", then you are probably talking about real mode in a 16 bit environment such as DOS or Windows 3.1, or in Virtual 8086 mode in Windows 95 or higher. In this mode, addressing is segmented into 65536 segments of 65536 bytes each, but each segment overlaps the next by only a 16 byte offset. This gives you addressability to 1048576 bytes. A far pointer is a 32 bit object, containing a 16 bit segment and a 16 bit offset. int __far *p; /* a far pointer called p which points to an int */


What does it mean by huge pointer is normalize give detail about far pointer huge pointer?

On far pointers the comparison operators(== and !=) check the 32 bit value. While >, =,


What is an far pointer?

In most modern computing environments, its just a pointer. If you're doing Win32 or similar, its just a keyword that means nothing. In older environments, such as MS-DOS, as I recall, a far pointer specifies both the data segment and the offset, whereas a near pointer only stored the offset. In a sufficiently small program, everything was in the same segment and the additional overhead of storing the segment information as well was not necessary.


What is far pointer in c language?

its pointer created for high safety that cant be find by anyone.


What is near far and huge pointers How many bytes are occupied by them?

Near, far, and huge pointers are different types of pointers used to reconcile the different addressing models of the Intel 8086/8088 class processors, running in a 16-bit operating system such as Windows 3.x, as well as any of the newer incarnations running in real mode or virtual 8086 mode.A near pointer can address something within one 64Kb memory segment, containing only an offset, and it takes two bytes. The segment is implied by context, and is usually the data segment, selected for the addressing model.A far pointer can address anything in the 1Mb memory1, containing both a segment and an offset, and it takes four bytes.A huge pointer is a normalised far pointer, which means its offset part is always between 00H and 0FH.In 32-bit mode a pointer can address anything in 4Gb memory, containing a flat 32-bit offset, and it takes four bytes. (In this mode segments have no significance.) It only works, however, when there is support for it, such as the WIN32 extension of Windows 3.x.---------------------------------------------------------------------------------------1In the 80286 or higher, running in protected mode, in OS/2, the segment portion of the pointer is actually a descriptor selector, so 1Mb addressibility depends on the operating system environment.far huge near pointer is an oxymoron. far points to memory outside of the normal address space. near points to memory within the normal address space, is the default, and usually is not needed. I've never seen huge before. What is the target architecture?Near, far, and huge pointers are a construct (usually) in the Win16 environment running on an 8086/8088 or later in real mode, such as Visual C/C++ 1.52. In this environment, near pointers are 16 bits, and far and huge pointers are 32 bits.