answersLogoWhite

0


Best Answer

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.

User Avatar

Wiki User

9y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is the memory representation of far and near pointers in C?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

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.


How to declare near and far pointers in C?

It used to be a good question 30 years ago. Right know you don't have to know anything about near and far pointers; but if you still use a 16-bit compiler, select 'Large Model' (or 'Huge Model'), and forget 'near' and 'far'


What settings do you need to use far keywords and other c style syntax in our programs while writing programs in VC?

There are no settings. Near and far pointers are specific to segmented memory models but when working with virtual memory models we always use normalised pointers which are always the same length (in bits). Near pointers use fewer bits than normalised pointers (usually half as many bits) because they only refer to the offset address within the current segment. Far pointers are similar to normalised pointers, except the high-order word refers to the segment address and the low-order word refers to the offset within that segment.


Why are header files not required when using far and near pointers?

In C programming, header files are required. It doesn't matter if you are using near pointers, far pointers, both, or neither -- you still need header files. There is no connection between the necessity of header files and the pointers' size.


When should a far pointer be used?

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


Why Near pointers are used for all code and data references in huge memory model for turbo C?

You may have misunderstood something. Choose Huge Model,and forget about near and far. (Honestly, this topic is outdated by twenty years!)


What are near pointers in c?

Just forget it, it was a question twenty years ago when we worked in MS-DOS with a 16/20 bit CPU. Near pointers contain 16 bits, far pointers contain 32 bits (but only 1MB (or 1MB+65520 bytes) are really addressible).


What is Normalization of pointers?

The 8085 had a 16-bit address bus thus it could address a maximum of 64KB of memory (2^16). The 8086 had a 20-bit address bus and could therefore address a maximum of 1MB of memory (2^20). To maintain compatibility, segmented memory was introduced, such that the segment and offset were stored in separate 16-bit registers. In order to perform 20-bit pointer arithmetic upon the 8086, the segment and offset had to be normalised by the compiler to produce a valid 20-bit address. This was achieved by left-shifting the segment by 4 bits and then adding on the offset. The 8086 also introduced the concept of near, far and huge pointers. A near pointer only stores the offset while far and huge pointers store both the segment and the offset. The only practical difference between far and huge pointers is in how pointer arithmetic works. With far pointers, only the offset is affected whereas with huge pointers, both the segment and the offset are affected.


How do you explain what near far and huge pointers are to a beginner?

If you're a beginner you don't need to worry about near and far pointers. They are a concept that have been obsoleted on most PCs. If you are programming for an embedded device, read the datasheet. It will explain it in terms of the device you are programming for.


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 tiny and small memory?

In x86 family of CPUs, there are six memory models. Memory is managed in "chunks" (segment or page) of 64K words. To find a specific location, the CPU needs to know the segment it is in and how far down (the offset) it is from the beginning of the segment. In addition, the x86 CPUs support three types of pointers: * near pointers access data in the specified segment * far pointers can access data within a 1MB address space * huge pointers are a type of far pointer, but with specialized behavior So applications written for the x86 world had to specify a type of memory model which detailed how pointers work. Generally speaking, the rules are: If code is under 64KB... and data is under 64KB... use Tiny or Small model If code is over 64KB... and data is under 64KB... use Medium model If code is under 64KB... and data is over 64KB... use Compact model If code is over 64KB... and data is over 64KB... use Large model


What is far and near pointer and how are they used?

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.