Question

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);
...
Was it helpful?

Solution

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

OTHER TIPS

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:

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

See here for documentation of cdecl in Microsoft.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top