C Language and Libraries Help (clang.hlp) (
Table of Contents;
Topic list)
Important Notice
The pages on this site contain documentation for very old MS-DOS software,
purely for historical purposes.
If you're looking for up-to-date documentation, particularly for programming,
you should not rely on the information found here, as it will be woefully
out of date.
__near
◄Up► ◄Contents► ◄Index► ◄Back►
─────C/C++ Language─────────────────────────────────────────────────────────
Keyword: __near
Syntax: type __near declarator
class __near class-name
class __near class-name func()
type member-func() __near
Summary: Specifies that a data object resides in the default
data segment. Specifies that a function can be called
only by functions in the same code segment. Functions and
data are referenced with 16-bit addresses, and pointers
declared as __near are 16-bit values.
See also: __based, __far, __huge
◄Memory Models►
The __near keyword can be used to modify data objects, pointers,
functions, classes, the this pointer of member functions, and the
addressing mode of objects returned by functions.
If the /Zc compiler switch is used, both near and _near are
synonyms for __near. If /Za is used, only __near is accepted.
NOTE: Do not use __near in a 32-bit program.
Data Objects or Pointers
A near data object resides in the default data segment.
A near pointer is a 16-bit value and can address locations
within the default segment, but not locations outside of it.
For example:
char __near a; // Char in default data segment
char __near *np; // Near pointer
The Calling Convention of Functions
A near function can be called only by other functions in the
same code segment. A pointer to a near function is a 16-bit value.
For example:
char __near redraw();
You can control the placement of functions within segments.
See: ◄__based►
Classes
Objects of a near class reside in the default data segment unless
an overriding keyword appears in the individual declaration.
Structure or union types can also be declared as __near.
For example:
class __near Node
{
// ...
};
Node my_node; // Near by default
Node __far your_node; // Explicitly declared __far
Member Functions
You can overload a member function to operate on near objects
if objects of the class are not near by default. Within the
function, the this pointer is a near pointer.
For example:
class Node
{
public:
void print() __near; // Called for near objects
void print(); // Called for default objects
private:
// ...
};
The Addressing Mode of Return Objects
You can specify that a function return a near object. This is
useful if you call a member function for the temporary object
returned by the function.
For example:
class __near Node make_node(); // Function returns a near Node
make_node().print(); // Call near print() for temporary
// object
-♦-