4

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);
...
Pietro M
  • 1,905
  • 3
  • 20
  • 24

2 Answers2

1

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

Mike Nakis
  • 56,297
  • 11
  • 110
  • 142
  • The problem is that that function is part of the "Microsoft Excel Developer's Kit, Version 14" (FRAMEWRK.H). I think I should not be supposed to modify it. – Pietro M Jan 06 '12 at 12:13
  • 2
    In that case, I think that FRAMEWRK.H was meant to be used with MSVC, not GCC. See if you can put something like `#define cdecl __cdecl` before including the header file. But I'm afraid that this is just the tip of the iceberg. – Mr Lister Jan 06 '12 at 12:27
  • @MrLister: you were right both about `#define cdecl __cdecl` and about the iceberg... Now I get errors about undeclared functions (e.g. `memcpy_s`) that are declared; they are global, included and path are set. – Pietro M Jan 06 '12 at 14:32
  • 1
    @PietroM I am afraid that if you are working so closely with Microsoft technologies, then a Microsoft Compiler is the way to go. – Mike Nakis Jan 06 '12 at 14:40
  • @MikeNakis: you are right. With a Microsoft compiler these issue are resolved. Thank you! – Pietro M Jan 10 '12 at 14:25
1

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.

Manikandan Sigamani
  • 1,964
  • 1
  • 15
  • 28
  • 1
    If you're going to copy code, you should also state the source - http://msdn.microsoft.com/en-us/library/zkwh89ks(v=vs.71).aspx – Luchian Grigore Jan 06 '12 at 12:13