I was won开发者_StackOverflowdering why in some source code there are these macros like FAR and PASCAL. What do they mean and do?
PASCAL: It's related to a calling convention. The parameters are pushed on the stack in left-to-right order (opposite of cdecl), and the callee is responsible for balancing the stack before return.
This calling convention was common in the following 16 bit APIs: OS/2 1.x and Microsoft Windows 3.x. There's some dispute over whether it was used by Borland Delphi 1.x
FAR: In a segmented architecture computer, a far pointer is a pointer which includes a segment selector, making it possible to point to addresses outside of the current segment.
For completeness, FAR and PASCAL are prepreocessor macros that, when compiled for 16-bit systems, expand to the keywords that were necessary to declare the calling convention and pointer size. On 32-bit systems, they generally expand to nothing (unless you have a weird default calling convention). The macros are retained for backward compatibility {hat/tip: comment from Adrian McCarthy}
Going by memory here,
FAR is a fall back to 16-bit days when heap memory was was segmented. NEAR data was limited in size and faster, FAR was allowed to be larger but more expensive.
To the best of my knowledge, in 32-bit land it's a macro that collapses to nothing.
PASCAL is a calling convention also used heavily in 16-bit days. It has since been replaced by stdcall.
Both are left in for backward compatibility.
FAR is obsolete; it was used in 16-bit code to indicate pointers that could address the entire address space, rather than just a 16-bit offset to the current segment.
PASCAL is a calling convention. As Wikipedia describes it:
The parameters are pushed on the stack in left-to-right order (opposite of cdecl), and the callee is responsible for balancing the stack before return.
This calling convention was common in the following 16 bit APIs: OS/2 1.x , Microsoft Windows 3.x, and Borland Delphi version 1.x.
FAR
is a holdover from the 16-bit era, when we had near (16-bit) and far (32-bit) pointers.
PASCAL
is a calling convention. I believe it's equivalent to stdcall
nowadays.
this is an old calling convention...
FAR is inherited from a time when processor registers where too small to hold the complete address of a jump destination. so, processors had 2 type of jump depending how "far" the destination was from the current program counter.
PASCAL describes the argument order on the stack, it tells that the function uses the order described by the Pascal programming language, which was different from C. (very old version of operating systems like MacOS and Windows where developped using Pascal).
It's probably some redundant / obsolete coding left over from the 16bit era.
FAR was used in 16 bit applications to indicated that the address required more than 16 bits.
PASCAL(altion) is a conversion type, it lets the compiler know how the stack is arranged (using PASCAL calling conventions) so that the compiler can pass the appropriate paramaters to and from the function.
HTH
Specifically PASCAL says the arguments to the function are passed in left to right order, this reduces the size of the code (because the caller knows how big the stack is and so can clean it up)
The C stdcall passes arguments right to left, this means you can have a variable number of arguments, but more code is needed for clear up.
精彩评论