> If comments above are valid, then shouldn't near pointer to nonnear object be defined like this
The comments above are valid. But "near pointer" means that a pointer can only point
to near objects, therefore a "near pointer to nonnear object" does not exist.
There are 2 distinct things __near can define.
For a pointer type __near defines if the pointer type is a near
or far pointer. This defines if an object of that type is 1 byte or 2 bytes in size, it also defines what kind of objects can be reached with the pointer.
In this context __near is defining the type of the object.
In order to define the type of a pointer, the __near keyword must placed just after the star.
E.g.
int *__near p1;
int *__near* p2;
The type of p1 is "int *__near", the type of p2 is "int *__near*".
In the case of p2 note that p2 itself is not a __near pointer, it just happens to point to one. So the size of p2 is 2 bytes (in the small memory model).
The second, independet topic is how the object itself is accessed.The compiler can either generate direct, 8 bit accesses or 16 bit externded addresses. This part is not specific to pointer, all kind of objects can have near access.
Also (and this is different from const) the __near access is not part of the type. It only aplies to the object.
For this use of __near, the keyword must be placed before the type, or for pointers it can also be listed after the type the pointer points to (if this is not itself a pointer).
E.g.
__near int in;
__near int* ip;
__near int** ip;
// Not recommended, easely confused with a near pointer type:
int __near * ip;
Here the near defines how the variables get accessed.
In real code using __near to define the access rarely is necessary. The __near object qualification on its own does not affect how the object gets allocated, so in order to be located in the zero page the object must also be allocated into a special section. By using a __DIRECT_SEG section qualifier, the __near object access gets the default for all object in such a section.
So using __near as an object qualifier is only necessary if the
default access to the section is not the right one. In practice that should rarely, if ever be the case.
So for variables to be placed into the zero page I would always write:
#pragma push
#pragma DATA_SEG __DIRECT_SEG ZERO_PAGE
int i;
int *__near pi = &i;
#pragma pop
The manual entry is obviously a copy paste bug.
Using __near (or const) after the int ("int __near i" or "int __near* ip") is equivalent to
using it before the int. But it is far more confusing in my opinion, so I'm always starting with the __near qualifier (for objects). Well as I said, code should rarely use __near for the object qualification anyway.
Daniel