Monday 28 November 2011

What is the difference between Windows functions and standard DOS functions? in C programming

What is the difference between Windows functions and standard DOS functions?

Unlike most DOS functions, Windows functions are always declared as FAR PASCAL. The FAR keyword signifies that the Windows API function is located in a different code segment than your program. AllWindows API function calls are declared as FAR, because all the Windows functions are located in dynamic link libraries and must be loaded at runtime into a different code segment than the one you are running your program in.

The PASCAL keyword signifies that the pascal calling convention is used. The pascal calling convention is  slightly more efficient than the default C calling convention. With regular non-pascal function calls, the parameters are pushed on the stack from right to left beginning with the last parameter. The code calling the
function is responsible for adjusting the stack pointer after the function returns. With the pascal calling sequence, the parameters are pushed on the stack from left to right, and the called function cleans up the stack. This method results in greater efficiency.

Note  that the capitalized words FAR and PASCAL are really uppercase representations of their lowercase keywords, far and pascal. Windows simply #defines them as uppercase to comply with notation rules. Also note that DOS functions can optionally be declared as far pascal—this is perfectly legal. However, under Windows, all API functions are FAR PASCAL. This is not an option, but a mandatory requirement of the Windows environment.

Cross Reference:

XXI.1: Can printf() be used in a Windows program?

No comments:

Post a Comment