Top Answer
User Avatar
Wiki User
Answered 2011-10-21 14:36:38

"near" and "far" pointers are actually non-standard qualifiers that you'll find only on x86 systems. They reflect the odd segmentation architecture of Intel processors. In short, a near pointer is an offset only, which refers to an address in a known segment. A far pointer is a compound value, containing both a segment number and an offset into that segment.

Segmentation still exists on Intel processors, but it is not used in any of the mainstream 32-bit operating systems developed for them, so you'll generally only find the "near" and "far" keywords in source code developed for Windows 3.x, MS-DOS, Xenix/80286, etc.

AnswerA near pointer is a 16 bit pointer to an object contained in the current segment, be it code segment, data segment, stack segment, or extra segment. The compiler can generate code with a near pointer and does not have to concern itself with segment addressing, so using near pointers is fastest, and generates smallest code. The limitation is that you can only access 64kb of data at a time, because that is the size of a segment - 64kb. A near pointer contains only the 16 bit offset of the object within the currently selected segment.

A far pointer is a 32 bit pointer to an object anywhere in memory. In order to use it, the compiler must allocate a segment register, load it with the segment portion of the pointer, and then reference memory using the offset portion of the pointer relative to the newly loaded segment register. This takes extra instructions and extra time, so it is the slowest and largest method of accessing memory, but it can access memory that is larger than 64kb, sometimes, such as when dealing with video memory, a needful thing. A far pointer contains a 16 bit segment part and a 16 bit offset part. Still, at any one instant of time, without "touching" segment registers, the program only has access to four 64kb chunks, or segments of memory. If there is a 100kb object involved, code will need to be written to consider its segmentation, even with far pointers.

Now, segments overlap. Each segment is 64kb in length, but each one overlaps the next and the prior by 65520 bytes. That means that every address in memory can be addressed by 64kb-1 different combinations of segment:offset pairs. The result is that the total addressible memory was only 1mb, and the total usable memory address space was 500kb to 600kb. That sounds odd, but Intel built it, Microsoft wrote it, and DOS/Windows 3.1 grew up around it. I still have that computer, and it still works just fine, thank you. :-)>

Now the huge pointer. The far pointer suffers because you can not just add one to it and have it point the the next item in memory - you have to consider segment:offset rules, because of the 16 byte offset issue. The huge pointer is a monolithic pointer to some item with a large chunk of memory, and there are no segment:offset boundaries.

Beautiful - huhh?? - well, in order to get that, the pointer to segment:offset calculation has to be done every time you reference the pointer. It does allow you to create and manipulate a single monolithic object that is greater than 64kb, but it has its costs.

Answerhi akreeti, far pointers are the normalized pointers of four bytes which are used to access the main memory of the computer ...it can access both the data segment and code segment thus by modifing the offset u can modify refer two different addresses but refer to the same memory . soumya AnswerHi all, In a generic OS , memory is organised in a segment:offset fashion. Now say,it is of "X" MB and this "X" MB is made up of say "S" number of segments of each segment having "B" Bytes where S*B Bytes=X MB.

Near Pointer: A near pointer is that which will only point within the current segment say segment 3 (there are S number of segments numbered 0 to S-1) by containing only offset .

Far Pointer: A far pointer is that which will point anywhere in the X MB across segments by containing segment+offset .

The numbers X,S and B vary across diff operating system memory models under which you are programming .

Say for MS-DOS,X=1MB;B=16 Bytes and S=1Mega Bytes/16 Bytes . Here, near poinetr will have 4 bits to express address from 0 to 16 Bytes in a segment . Here, far pointer will have "l" bits for segment part of memory where 2^l=S (Here S should be a multiple of 16 bytes i.e; B=offset memory) and 4 bits for offset part of memory . so far poinetr will have l+4 bits .

Thanks Chandra

AnswerIn DOS only 1 mb (10,48,580 bytes) of memory is accessible. Any of these memory locations are accessed using CPU registers. Under DOS the CPU registers are only 16 bits long. Therefore, the minimum value present in a CPU register could be 0, and maximum 65,535. Then how do we access memory locations beyond 65535th byte? By using two registers (segment and offset) in conjunction. For this the total memory (1 mb) is divided into a number of units each comprising 65,536 (64 kb) locations. Each such unit is called a segment. Each segment always begins at a location number which is exactly divisible by 16. The segment register contains the address where a segment begins, whereas the offset register contains the offset of the data/code from where the segment begins. For example, let us consider the first byte in B block of video memory. The segment address of video memory is B0000h (20-bit address), whereas the offset value of the first byte in the upper 32K block of this segment is 8000h. Since 8000h is a 16-bit address it can be easily placed in the offset register, but how do we store the 20-bit address B0000h in a 16-bit segment register? For this out of B0000h only first four hex digits (16 bits) are stored in segment register. We can afford to do this because a segment address is always a multiple of 16 and hence always contains a 0 as the last digit. Therefore, the first byte in the upper 32K chunk of B block of video memory is referred using segment:offset format as B000h:8000h. Thus, the offset register works relative to segment register. Using both these, we can point to a specific location anywhere in the 1 mb address space.

Suppose we want to write a character `A' at location B000:8000. We must convert this address into a form which C understands. This is done by simply writing the segment and offset addresses side by side to obtain a 32 bit address. In our example this address would be 0xB0008000. Now whether C would support this 32 bit address or not depends upon the memory model in use. For example, if we are using a large data model (compact, large, huge) the above address is acceptable. This is because in these models all pointers to data are 32 bits long. As against this, if we are using a small data model (tiny, small, medium) the above address won't work since in these models each pointer is 16 bits long.

What if we are working in small data model and still want to access the first byte of the upper 32K chunk of B block of video memory? In such cases both Microsoft C and Turbo C provide a keyword called far.

Answernormally Pointers are 32 bit length. which are divided as segment and offset.

which are represent as

seg : off 0000:0000 . . . 8000:FFFF. . . . FFFF:FFFF

first 4 hexa digits are segment, last 4 hexa digits are offset

C Program will allocate 64KB (only one segment) memory for data Part (dynamic memory allocation, Local variables).

by using 16 bit we can access that memory that's called near pointer(16 bit pointer).

suppose we need more than 64KB memory to a program / we want to access a particular memory location (in TSR Program)

at the time we neet 32 bit pointer. through 32 bit pointer we can access any segment and offset address.

there are 2 types of 32 bit pointers 1. far pointer. 2. Huge Pointer.

In TSR programming normally we use far Pointer.

The Main Difference between Far and Huge Pointer is

Far pointers are not Normalized.

Huge pointers are Normalized.

AnswerFirst let me state this is based on my current understanding. If someone can update or improove my version I will be grateful:

1.For those in hurry far simply means "its not here find it somewhere else in memory" 2. far, near and huge and not a part of the C standard( am I right?)

-So the answer to this is: "It depends" Its highly compiler specific and platform(processor) specific.

Different processors have different ways to handle memory, and also different amount of memory.

when you say "far" you are just telling the compiler find or put this data somewhere else.But the compiler does the hard work for you: writing the instructions to change the segment properly and accessing the correct memory location for you..and that's because it knows the processor..

I think previous answers are mostly related to Pentium family of processors..and perhaps turbo C or similar compilers.But remember that is only one of them!

Below are the examples which perhaps can have different meanings in different places:

1. far int* near a; 2. far int* a; 3. far int *far a;

So the best way is to try out with your compiler and find out

hope that helped!

AnswerPointers can either be near, far, or huge. Near pointers refer to the current segment, so neither DS nor CS must be modified to dereference the pointer. They are the fastest pointers, but are limited to point to 64 kilobytes of memory (the current segment).

Far pointers contain the new value of DS or CS within them. To use them the register must be changed, the memory dereferenced, and then the register restored. They may reference up to 1 megabyte of memory. Note that pointer arithmetic (addition and subtraction) does not modify the segment portion of the pointer, only its offset. Operations which exceed the bounds of zero or 65535 (0xFFFF) will undergo modulo 64K operation just as any normal 16 bit operation.

For example, the code below will wrap around and overwrite itself: char far* myfarptr = (char far*) 0x50000000L ; unsigned long counter ; for(counter=0; counter<128*1024; counter++) // access 128K memory *(myfarptr+counter) = 7 ; // write all 7s into it

The moment counter becomes (0x10000), the resulting absolute address will roll over to 0x5000:0000.

Huge pointers are essentially far pointers, but are normalized every time they are modified so that they have the highest possible segment for that address. This is very slow but allows the pointer to point to multiple segments, and allows for accurate pointer comparisons, as if the platform were a flat memory model: It forbids the aliasing of memory as described above, so two huge pointers that reference the same memory location are always equal.

This near, far & huge pointers comes only in DOS or other, which have only less memory accessible. In DOS only 1 Mb ( 10,48,580 Bytes) of memory is accessible. Any of these memory location are accessed using CPU registers. Under DOS the CPU registers are only 16 bits long. Therefore, the minimum value present in a CPU register is 0, and maximum is 65,535. If we want to access more than 65,535 ? how to ? We can do this by - using two registers ( Segment & Offset ). Here memory is divided into 64 Kb locations or chunks. C Program will allocate 64KB (only one segment) memory for data Part (dynamic memory allocation, Local variables). by using 16 bit we can access that memory that's called near pointer(16 bit pointer). suppose we need more than 64KB memory to a program / we want to access a particular memory location (in TSR Program) at the time we need 32 bit pointer. through 32 bit pointer we can access any segment and offset address. The Main Difference between Far and Huge Pointer is Far pointers are not Normalized. Ex: TSR Programs use Far Pointers Huge pointers are Normalized. I think by this u can have brief idea about near, far & huge pointers. According to my knowledge far pointers are mainly used to build I/O commands.Such as you can write "printf" function by using far pointer void main() { char far *vdu=0xB8000000; *(vdu+2)='a'; } If you run this program in C,you can see "a" in the DOS screen There are 2 blocks of memory above the 640KB RAM of 64KB each. The first 32KB are used by MA, rest by CGA/EGA/VGA. The "far" pointer is used to access the VDU memory directly. Hence the displaying functions or output functions are not required.

AnswerOn 16-bit operating systems, a huge pointer allows the developer to access a single block of memory that's larger than 64 kilobytes in size.
User Avatar

Your Answer

Still Have Questions?

Related Questions

What are the syntax of turbo c language?

Standard C with little extensions like near, far, huge and _seg pointers.

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'

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.

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!)

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.

How many bytes are occupied by near pointers in c?

Note that near and far pointers are outdated by twenty years, but if you still want to know, the answer is two bytes.

What are different type of pointers?

Pointer is a variable that is used to store the memory address of another variable. There are differenr types of pointers: NULL pointer THIS pointer VOID pointer NEAR pointer HUGE pointer FAR pointer WILD pointer

When should a far pointer be used?

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

What are huge and dangling pointers in C language?

A huge pointer was a special type of pointer used in the WIN161 environment that would allow you to monolithically handle objects of size greater than 64KB as if that were one single address space. If you had the special WIN32 add-on installed, you could declare and use huge pointers natively, but normally, you had to do address translation to go from huge to far and from far to huge.A dangling pointer is not something I have heard of. The closest I can interpret this is a misunderstanding of dangling if statements, although it could be a reference to leaking memory through unallocated pointers that go out of scope before they are freed. Please restate the question, with better details.1 Today, with true 32 and 64 bit operating systems abounding, the concept of near, far, and huge pointers is obsolete and archaic. The need to deal with them disappeared with Visual Studio 1.52 and Windows 3.1. (Of which I still have working copies. :-)>)

What is the use of huge pointer in C?

It has to do with the memory model you are using... If you are using the LARGE or HUGE memory model, then you use HUGE memory pointers. == Huge pointers are like far pointers, just more so: they are always normalized (ie offset part is between 0 and 15), and segment wrapping-around do not occur if you use them.

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.

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 &gt;, =,

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.

How do you use far pointer in c?

Far and near pointers are DOS-specific trouble-makers, you should just forget them... If you are still using TurboC from the previous centaury, simpy select memory modell "Large", and all your pointers will be 'far' by default.

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 the difference between far pointer and huge pointer in C programming language?

Huge pointers are fully recognised and evaluated for their entire width.Far pointers only allow normal operations to be done to their offset amount and not the segment or paragraph amount.AnswerNear pointers have a size of 2 bytes. They only store the offset of the address the pointer is referencing. An address consisting of only an offset has a range of 0 - 64K bytes starting from the beginning of DGROUP. A near pointer can be incremented and decremented using arithmetic operators (+, -, ++, and --) through the entire address range. Any attempt to increment a near pointer that has a value of 64K (0xffff) will result in a value of 0. This is referred to as wrapping the pointer. A corresponding result can be expected when attempting to decrement a pointer that contains an address of 0, except the result will be 64K instead of 0. In addition to being incremented and decremented, near pointers can be compared to one another using relational operators ( , ==, >= and Ref: http://bdn.borland.com/article/0,1410,18049,00.HTMLManu Dhawan

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.

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.

How can you access the administrator password using pointers in C?

i don't have any knowledge about your ques. but i guide you to read the "Writing TSR through C" &amp; learn knowledge of FAR &amp; HUGE ponters.by this you can access the adminstrator password using pointers in C.

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.

Can char pointer contain long address in c?

What do you mean by 'long address'?1. If you are asking about 'near' and 'far' pointers, then you should forget them; simply use Huge Memory Model.2. If you mean the address of a 'long int'-type variable, then yes, with type-cast:long l;char *p = (char *)&l;Note: for generic pointers you can use type void *

Far pointer size in C plus plus?

A far pointer is 4 bytes; 2 bytes for the segment, and 2 bytes for the offset.Far and near pointers were used in older, obsolete environments based on the 8086/8088 architecture, such as Windows 3.x and DOS. Modern operating systems, such as Windows XP, Vista, or 7, on a newer processor such as a Core 2, use a linear space where the pointer is more correctly called a huge pointer - the terms near and far are no longer used.Note: sizeof (char far *) will tell you in bytes.

In which cases should you use the far pointers?

Far pointers are generally used with 16 bit windows application. You can also use for DOS based application for accessing VDU memory since it has huge pointer and it can be fit into the far pointers. Well, Win32 does not distinguish between near and far addresses. Because the types NEAR and FAR are defined in WINDEF.H, they are automatically handled by the include file, which redefines them as empty strings for Win32. Thus, NEAR and FAR are ignored. If you do not include WINDEF.H, a convenient solution is to use the /D command-line option to replace the keywords by empty strings. For example: /D_near= /D_far= /D__near= /D__far= The increased address-space size in 32-bit Windows impacts 16-bit code in several ways: Pointers are all 32 bits wide and are no longer near or far, and your code cannot make assumptions based on segmented memory. Window handles, handles to other objects (such as pens, brushes, and menus), and graphics coordinates have increased to 32 bits. Thus, you cannot use types such as WORD interchangeably with HWND as you could in 16-bit Windows. Message handlers must be rewritten because the different sizes can change the way information is packed in some message parameters. The larger size of graphics coordinates affects a number of function calls. The key areas of 16-bit code affected by these changes are: Window procedure declarations, Near and far type declarations, Data types, Messages, Calls to API functions, WinMain function

What is the difference between near far and huge pointers?

All three of these pointer types are specific to the Intel x86 segmented architecture, and those processors that emulate this architecture. Segmented architecture here refers to memory access. A memory address in this scenario could be an offset from a segment register. The near pointer is a 16-bit entity that contains just the offset from the default data segment register. The far pointer contains the segment address and the offset in a dual 16-bit structure. The huge pointer is the actual memory address, without reference to any segment register.

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').

Still have questions?

Trending Questions
How to Make Money Online? Asked By Wiki User
Best foods for weight loss? Asked By Wiki User
Does Neil Robertson wear a wig? Asked By Wiki User
Unanswered Questions