tags:

views:

1245

answers:

3

can any body tell the difference between far pointer and near pointer in C?

+3  A: 

I can't, but I think wikipedia can.

Suppressingfire
bah - beat me too it... I was going to paste the same link!
thrope
Have an upvote on your comment, then :-)
Suppressingfire
+10  A: 

Far and near pointers were used in old platforms like DOS.

I don't think they're relevant in modern platforms. But you can learn about them here and here (as pointed by other answers). Basically, a far pointer is a way to extend the addressable memory in a computer. I.E., address more than 64k of memory in a 16bit platform.

Pablo Santa Cruz
I believe some operating systems can access more than 4GB of memory on a 32-bit system. In this case such extended pointer types are necessary. However it is rare for the operating system to allow user mode applications access to more than 4GB in such an environment.
PP
+10  A: 

To quote Wikipedia,

Four registers are used to refer to four segments on the 16-bit x86 segmented memory architecture. DS (data segment), CS (code segment), SS (stack segment), and ES (extra segment). A logical address on this platform is written segment:offset, in hexadecimal.

Near pointers refer (as an offset) to the current segment.

Far pointers use segment info and an offset to point across segments. So, to use them, DS or CS must be changed to the specified value, the memory will be dereferenced and then the original value of DS/CS restored. Note that pointer arithmetic on them doesn't modify the segment portion of the pointer, so overflowing the offset will just wrap it around.

And then there are huge pointers, which are normalized to have the highest possible segment for a given address (contrary to far pointers).

On 32-bit and 64-bit architectures, memory models are using segments differently, or not at all.

Michael Foukarakis
This would be clearer if you explain what a segment (and an offset in the case of one) is. "Segments" as used by DOS are a little arcane, imho.
quark
They are not arcane. They are insane.
Stefano Borini