cdecl错误:之前应为初始值设定项

cdecl error: expected initializer before

本文关键字:错误 cdecl      更新时间:2023-10-16

我对cdecl调用约定有问题:

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

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

谢谢!

平台:Windows 7;MinGW;GCC 4.6.1


我不能修改这些函数,因为它们是文件FRAMEWRK.H:中"Microsoft Excel Developer’s Kit,Version 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);
...

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

用两个下划线作为前缀,如下所示:__cdecl

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

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

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

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