what is difference between this,far,near pointer?

R

rahul8143

hello,
I require a single c++ program that will illustrate usage of
this,far,near pointers. Can any body please explain me those pointers?
regards,
rahul.
 
V

Victor Bazarov

I require a single c++ program that will illustrate usage of
this,far,near pointers. Can any body please explain me those pointers?

'this' is a pointer to the object for which a non-static member function
was invoked (couldn't you look it up in your favorite C++ book?)

Neither "far" nor "near" pointers are defined in C++ _language_, please
refer to the compiler documentation that describes them. They are not
any standard concepts, they represent extensions to the language.

V
 
R

Ron Natalie

hello,
I require a single c++ program that will illustrate usage of
this,far,near pointers. Can any body please explain me those pointers?
regards,
rahul.
The "this" pointer is defined within non-static member functions and
refers to the object on which the member is invoked.

There is no such thing in the language as "near" or "far" pointers.
That was a disgusting crutch by poor compilers on arcane architectures.
 
A

Alf P. Steinbach

* (e-mail address removed):
I require a single c++ program that will illustrate usage of
this,far,near pointers. Can any body please explain me those pointers?

'this' is part of standard C++. Within a member function it's a pointer to
the object the member function has been called on. So when you write

o.foo();

then within 'foo', for this execution, 'this' will point to the object 'o'.

'far' and 'near' are non-standard extensions. They were used in C and C++
on 16-bit DOS and MS-Windows platforms. There a 'near' pointer was a 16-bit
offset into a region of memory, with implicit start address (the implicit
start address depended on the context, which made this optimization a risky
business -- whole books have been written about it). 'far' was a 32-bit
pointer consisting of a 16-bit 'selector' that indirectly determined the
start address of the memory region, and a 16-bit offset into that region.

Today few, if any, C++ compilers support 'far' and 'near'. In modern 32-bit
Windows (say, this is actually mostly independent of modern OS) a pointer is
usually just a 32-bit offset into a region of memory. Since data and
function pointers are two different kinds of beast in C++ it's theoretically
possible that a function pointer may be an offset into a different region of
memory than a data pointer, but in practice that's not so. Anyway, the
hardware may support larger pointers; e.g., the processor in a Windows/Intel
PC supports 48-bit pointers consisting of a 16-bit 'selector' and a 32-bit
offset, but ordinary C++ compilers don't support such 48-bit 'far' pointers.

Now, region of memory. I've used that above to refer to the process'
_logical_ address space. On modern computers logical addresses will usually
be translated by the OS and hardware to physical addresses, so C++ pointers
are usually not directly memory addresses, and the address space they refer
to is usually not a contigous region of physical memory.

However, on a microcontroller, say, a C++ pointer can be a physical memory
address.
 
P

Peter Julian

hello,
I require a single c++ program that will illustrate usage of
this,far,near pointers. Can any body please explain me those pointers?
regards,
rahul.

Your confused between this, which is a pointer to an object (usually
attached to the object's non-static member functions) and far/near which are
obsolete addressing schemes.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top