| |
 | Posted by Achilleas Margaritis in reply to Walter | Permalink Reply |
|
Achilleas Margaritis 
Posted in reply to Walter
| Walter wrote:
> "Achilleas Margaritis" <Achilleas_member@pathlink.com> wrote in message
> news:c68c6f$1vsp$1@digitaldaemon.com...
>
>>According to Microsoft documentation, WINAPI is FAR PASCAL and PASCAL is
>>_pascal. But _pascal is obsolete, and it means __stdcall. So, it seems
>
> that for
>
>>D, extern(Windows) and extern(Pascal) is the same. Is there any difference
>
> ? Is
>
>>Pascal really needed ?
>
>
> They are different, both in name mangling and in calling convention, and
> both are needed because C code on Win32 uses both.
>
>
Excuse me if I insist, but here is a piece from MSDN:
/////////////////////////////////////////////////////////////////////////////////
Obsolete Calling Conventions
Home | Overview | How Do I
The __pascal, __fortran, and __syscall calling conventions are no longer supported. You can emulate their functionality by using one of the supported calling conventions and appropriate linker options.
WINDOWS.H now supports the WINAPI macro, which translates to the appropriate calling convention for the target. Use WINAPI where you previously used PASCAL or __far __pascal.
/////////////////////////////////////////////////////////////////////////////////
Here is the piece about __stdcall:
/////////////////////////////////////////////////////////////////////////////////
__stdcall
Home | Overview | How Do I
Microsoft Specific —>
The __stdcall calling convention is used to call Win32 API functions. The callee cleans the stack, so the compiler makes vararg functions __cdecl. Functions that use this calling convention require a function prototype. The following list shows the implementation of this calling convention.
Element Implementation
Argument-passing order Right to left.
Argument-passing convention By value, unless a pointer or reference type is passed.
Stack-maintenance responsibility Called function pops its own arguments from the stack.
Name-decoration convention An underscore (_) is prefixed to the name. The name is followed by the at sign (@) followed by the number of bytes (in decimal) in the argument list. Therefore, the function declared as int func( int a, double b ) is decorated as follows: _func@12
Case-translation convention None
The /Gz compiler option specifies __stdcall for all functions not explicitly declared with a different calling convention.
Functions declared using the __stdcall modifier return values the same way as functions declared using __cdecl.
END Microsoft Specific
Example
In the following example, use of __stdcall results in all WINAPI function types being handled as a standard call:
// Example of the __stdcall keyword
#define WINAPI __stdcall
/////////////////////////////////////////////////////////////////////////////////
The first piece from MSDN says that _pascal is obsolete.
The second piece says that WINAPI = _stdcall.
The following table shows the Microsoft calling conventions:
http://www.cs.cornell.edu/courses/cs412/2001sp/resources/microsoft-calling-conventions.html
It seems that _pascal is really obsolete.
Of course, Walter, you are much more experienced, so I believe you, but why does Microsoft say that _pascal is obsolete ?
|