D - Difference of Windows/Pascal calling conventions ?
- Achilleas Margaritis (4/4) Apr 22 2004 According to Microsoft documentation, WINAPI is FAR PASCAL and PASCAL is
- Stewart Gordon (11/15) Apr 22 2004 In that case, extern(Windows) is syntactic sugar for extern(Pascal)
- Walter (6/10) Apr 22 2004 that for
- Achilleas Margaritis (49/68) Apr 22 2004 Excuse me if I insist, but here is a piece from MSDN:
- Walter (5/7) Apr 22 2004 why does
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 ?
Apr 22 2004
Achilleas Margaritis wrote: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 ?In that case, extern(Windows) is syntactic sugar for extern(Pascal) rather than the other way round. So it makes more sense to ask if Windows is really needed. I'd leave them both in. That way, you can make it clear which you're interfacing - Pascal code or Windows API. Stewart. -- My e-mail is valid but not my primary mailbox, aside from its being the unfortunate victim of intensive mail-bombing at the moment. Please keep replies on the 'group where everyone may benefit.
Apr 22 2004
"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 seemsthat forD, extern(Windows) and extern(Pascal) is the same. Is there any difference? IsPascal really needed ?They are different, both in name mangling and in calling convention, and both are needed because C code on Win32 uses both.
Apr 22 2004
Walter wrote:"Achilleas Margaritis" <Achilleas_member pathlink.com> wrote in message news:c68c6f$1vsp$1 digitaldaemon.com...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 ?According to Microsoft documentation, WINAPI is FAR PASCAL and PASCAL is _pascal. But _pascal is obsolete, and it means __stdcall. So, it seemsthat forD, extern(Windows) and extern(Pascal) is the same. Is there any difference? IsPascal really needed ?They are different, both in name mangling and in calling convention, and both are needed because C code on Win32 uses both.
Apr 22 2004
"Achilleas Margaritis" <axilmar b-online.gr> wrote in message news:c69d0m$klo$1 digitaldaemon.com...Of course, Walter, you are much more experienced, so I believe you, butwhy doesMicrosoft say that _pascal is obsolete ?I wouldn't use it in any new code. But existing legacy C code uses it, and so it must be supported.
Apr 22 2004