在看书的时候,看到'PASCAL'一词的出现,但是完全不理解它的用法~以前没接触过~
这本书是在这论坛上看到人家介绍的,<深入浅出MFC>,
希望有这本书的人,可以翻翻看,为我解释解释~~~诚谢啊!
Page 97
struct
{
  ...
  CObject* (PASCAL* m_pfnCreateObject)();
  ...
}Page 116
CObject* pObject;
pObject = (*m_pfnCreateObject)();以前见过对'PASCAL'使用,所以请解释详细点~非常感谢!!!!!!
在此,代表菜鸟同志们,向答题者致敬!∠○
                                                                          

解决方案 »

  1.   

    在 windef.h 中#define PASCAL      __stdcall
    #define WINAPI __stdcall
    是函数的一种编译约束或描述了,我说的不严密啊。
    与之对应的还有一种 __cdecl 区别:
    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.
    This is the default calling convention for C and C++ programs. Because the stack is cleaned up by the caller, it can do vararg functions. The __cdecl calling convention creates larger executables than __stdcall, because it requires each function call to include stack cleanup code. The following list shows the implementation of this calling convention.
      

  2.   

    pascal就是参数从左往右入栈,被调用端从右往左访问堆栈,并且被调用端清除堆栈。这种设定可以省去调用端几个字节的指令(因为通常每个函数不只被调用一次,所以被调用得越多越省……不过即使你在程序里面call了1000遍也不过省了几K字节而已,呵呵)。这种设定的弊端在于参数数量成了固定的了,没办法定义向printf之类的可变参数函数。
      

  3.   

    这里的PASCAL是指函数调用时传递参数的规则,PASCAL与__stdcall相同,函数调用时参数从右到左依次压栈,函数返回时清栈。
    此外还有__cdecl、__thiscall、__fastcall。函数定义时指定用哪种规则来传递参数,如果没有指定则使用默认的规则。再强制转换函数指针要注意,传递参数的规则必须相同,其它情况可不必考虑。