cdecl 错误:之前需要初始化程序
我对 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
我无法修改这些函数,因为它们是“Microsoft Excel Developer's Kit,版本 14”的一部分,位于文件 FRAMEWRK.H 中:
///***************************************************************************
// 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);
...
I have a problem with the cdecl calling convention:
void Test1(char* str, ...) // ok
{}
void cdecl Test2(char* str, ...) // error: expected initializer before 'Test2'
{}
int main()
{}
What should I do to make the compiler recognize the cdecl calling convention?
Thanks!
Platform: Windows 7; MinGW; GCC 4.6.1
I cannot modify those functions, since they are part of "Microsoft Excel Developer's Kit, Version 14", in the file FRAMEWRK.H:
///***************************************************************************
// 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);
...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
编辑注意:这个答案(以及所有类似的答案)在技术上是不正确的,如下面的评论所示。我不会删除它,这样我们就不会丢失评论。 (END EDIT)
在其前面添加两个下划线,如下所示:
__cdecl
EDIT Note: this answer (and all answers similar to it) is technically incorrect, as the comments below indicate. I am not removing it, so that we do not lose the comments. (END EDIT)
Prepend it with two underscores, like this:
__cdecl
这是 C 和 C++ 程序的默认调用约定。将 __cdecl 修饰符放在变量或函数名称之前
指示编译器对系统函数使用 C 命名和调用约定:
请参阅 此处获取 Microsoft 中的 cdecl 文档。
This is the default calling convention for C and C++ programs. Place the __cdecl modifier before a variable or a function name
The compiler is instructed to use C naming and calling conventions for the system function:
See here for documentation of cdecl in Microsoft.