I noticed 2 keywords from a C code listings that I have seen. These are "near" and "far". They are used as shown in the c code snipets below
char far Flash_Page[PAGE_SIZE];
char near RamByte;
What are the keywords "near" and "far" for?
What does each statement in the above C Code Snipets mean? I know that they are a variable declaration of some sort but since it used the "near" and "far" keywords I dont know its complete meaning.
So does this mean that the Flash_Page is a 32-bit pointer while the near is a 16-bit pointer?
If so how do you dereference them? Do you still use the Asteris (*) before the indentifier to mean that its the contents of the mem loc that it is pointing to that you are interested in and not the memloc it self?
You can use them normally -- the only difference is when you declare them you are also declaring their storage requirements. For example, here's how to manipulate the console text color under DOS on an EGA or VGA card (by directly accessing the BIOS data area)
1 2 3 4 5 6 7 8
// EGA/VGA BIOS current text attribute
staticunsignedchar far *BIOS_current_color_attribute = MK_FP( 0, 0x466 );
unsignedchar save = *BIOS_current_color_attribute;
*BIOS_current_color_attribute = 0x1E; // yellow on dark blue
printf( "Hello world!" );
*BIOS_current_color_attribute = save;
printf( "\n" );
You only really need to worry about the difference in far and near pointers when compiling in tiny, small, or medium memory models -- in other modes all pointers are far by default (and introducing near pointers can be disasterous).
They're pointers for different memory models and as such have their own pointer arithmetic. It doesn't really make much sense without understanding the context in which they were used.
The Intel 16bit x86 architecture organised memory as overlapping 64k segments. If you wanted a pointer that was only used within a segment, you used a near pointer. If it needed to go beyond a segment, you needed a far pointer. The huge pointer was introduced later by Borland and was as large as a far pointer, but the arithmetic was done in such a way that you could compare them without having to worry about the segment:offset notation that made far pointers difficult to compare.
Intel 32bit x86 architecture still uses segments, but they're all 4G and all start at zero and so overlap, removing the need for the complicated segment:offset addressing scheme as pointers to different segments all take the same value.
The notion of memory model is a powerful one as it allows you an address range larger than your machine word size.
In C++, the STL's allocator was meant to encapsulate the memory model notion.