C + + far near

Source: Internet
Author: User

The microprocessor (CPU) component of 80286 is indeed a 16-bit machine, and the Windows operating system (including DOS) is segmented for memory (segmented memory mode, Segment Memory modes). Windows 1.0-3.1, which runs on these 16-bit CPU computers, is called "Win16." Starting with the 32-bit CPU starting at 80386, this segmented memory pattern is also used for compatibility, which results in the appearance of near (short), far (long) pointers.

On 32-bit machines starting with Windows 95, Windows supports the 32-bit flat memory mode (which distinguishes it from the segmented memory mode), and, correspondingly, Windows 95 after Windows is what we often call "Win32." Programs written for Win32 use a 32-bit linear address space.

This shows that if you want to write on the Win16 can also run the program, will involve the concept of NEWR, far pointers. On the WIN32, the pointer has no near, far distinction.

Source Documents

Storage attributes: C pointers have three storage properties, respectively:

Near (near) pointer: offset address in 16-bit segment

Far (FAR) pointer: 16-bit address + 16-bit offset address

Huge (giant) pointers: 32-bit normalized, unique memory addresses

The storage properties of the C language are determined by six compilation modes (see the Option->compiler->model option in the TC Integrated Environment menu), the default compilation mode is small, and in this compilation mode, the default property of the pointer is near.

Source Documents

The difference between near and far in C + +

The keywords near and far are affected by the target computer architecture. Not much is currently being used in programming.

The NEAR keyword creates a target pointer to the lower portion of addressable memory. These pointers occupy a single byte of memory, and the memory units they can point to are limited to 256 locations, usually in the 0X0000~0X00FF range.

int near * PTR;

The FAR keyword creates a pointer that can point to any data in memory:

char FAR * PTR;

Near (near) pointer: offset address in 16-bit segment

Far (FAR) pointer: 16-bit address + 16-bit offset address

Huge (giant) pointers: 32-bit normalized, unique memory addresses

The storage properties of the C language are determined by six compilation modes (see the Option->compiler->model option in the TC Integrated Environment menu), the default compilation mode is small, and in this compilation mode, the default property of the pointer is near.

Add: Near pointer is a 16-bit pointer, relies on a segment address register, pointer variable is displacement, using segment address register + pointer to addressing, so there is a 64K limit.

Far pointer is a 32-bit pointer, not only 16-bit displacement, but also 16-bit address, but this pointer has a flaw, increment only add to the displacement portion, once the 16-bit displacement exceeds the FFFF will return to the initial address of this segment.

So, with the introduction of the huge pointer, the huge pointer is the same as far, the difference is only in the use of standardized methods to represent, so that all addresses have a unique representation, thus avoiding the problem of far pointers.

The null pointer states a pointer state, without the null pointer, as if the number were not 0.

Source Documents

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.