tags:

views:

385

answers:

3

Hello,

Without knowing i typed 'far' instead of 'var' by my mistake.I noticed the keyword is bold ,which gives me the thoughts that it's part of Delphi's syntax.

Does anyone know anything about "far" keyword?

+7  A: 

Far means nothing in 32-bit versions of Delphi (Delphi 2 and later). It was used in 16-bit programming to indicate segment location.

It's still in the language strictly for backward compatibility with very old legacy code.

From the old Delphi 7 help file, topic "Calling conventions":

"The directives near, far, and export refer to calling conventions in 16-bit Windows programming. They have no effect in 32-bit applications and are maintained for backward compatibility only."

Ken White
+8  A: 

As Ken White explained, it's only used in 16 bit applications.

As a 16 bit pointer only can address 64 kb of memory, memory segments are used to access more memory. The processor has four segment registers so it can have four active segments at the same time, a code segment (cs), a data segment (ds), a stack segment (ss) and an extra segment (es). Each segment is 64 kb, but they may address the same memory area or party overlap.

A near pointer is a 16 bit pointer inside the same segment. It's used as a pointer to data or code in the same module.

A far pointer is a 16+16 bit pointer consisting of a 16 bit segment offset and a near pointer. It's used as a pointer to data or code in a different module. When you use a far pointer to call a procedure, the segment part is put in the cs and ds registers (IIRC) to access the code and data in that module.

The physical address of a segment+pointer pair is calculated as segment * 16 + pointer. That means that a 16 bit program can address 1024 kB of memory. To get access to more memory the two techniques of extended and expanded memory is used. (Also the high memory technique to some extent, where the address would not wrap at a 1 MB barrier, but using the segment offset FFFF would give you direct access to 65520 bytes of extended memory.)

Guffa
Near pointers were never supported. The Far keyword applied to procedures declared in the implementation but which you wanted to use far calling conventions so if they were called via a pointer they would execute a far return rather than a near return.
Loren Pechtel
The keyword dates back beyond Delphi 1, to Borland/Turbo Pascal...
Guffa
+1  A: 

It may return. I have heard murmurs of a trend to look at PAE with all these x64 CPUs floating around. So you program can address the normal 2 or 3 Gig mem limit (OS boot setting dependend), but have an 48 bit pointer that can address another 4 gig. Of course you have to have lots of cheap DDR3 physical memory installed. Say 24 Gig. Not too many programs that need more than 3 gig core. Swap file managment means that not all of your running program is on memory anyway. But maybe is data to scan or process.

So far may return as a 48 bit pointer to help the transition from 32 to 64 bit adressing.