4

我对 cdecl 调用约定有疑问:

void Test1(char* str, ...)           // ok
{}

void cdecl Test2(char* str, ...)     // error: expected initializer before 'Test2'
{}

int main()
{}

我应该怎么做才能让编译器识别 cdecl 调用约定?

谢谢!

平台:Windows 7;明威;GCC 4.6.1


我无法修改这些函数,因为它们是文件 FRAMEWRK.H 中“Microsoft Excel 开发工具包,版本 14”的一部分:

///***************************************************************************
// File:        FRAMEWRK.H
//
// Purpose:     Header file for Framework library
//
// Platform:    Microsoft Windows
//...
// From the Microsoft Excel Developer's Kit, Version 14
// Copyright (c) 1997 - 2010 Microsoft Corporation. All rights reserved.
///***************************************************************************
...
// 
// Function prototypes
//

#ifdef __cplusplus
extern "C" {
#endif

void far cdecl debugPrintf(LPSTR lpFormat, ...);
LPSTR GetTempMemory(size_t cBytes);
void FreeAllTempMemory(void);
...
4

2 回答 2

1

编辑注意:这个答案(以及所有类似的答案)在技术上是不正确的,如下面的评论所示。我不会删除它,这样我们就不会丢失评论。(结束编辑

在它前面加上两个下划线,如下所示:__cdecl

于 2012-01-06T12:05:10.133 回答
1

这是 C 和 C++ 程序的默认调用约定。将 __cdecl 修饰符放在变量或函数名之前

编译器被指示为系统函数使用 C 命名和调用约定:

// Example of the __cdecl keyword
_CRTIMP int __cdecl system(const char *);

有关 Microsoft 中 cdecl 的文档,请参见此处

于 2012-01-06T12:13:06.567 回答