开发者

function pointers error C2373: redefinition; different type modifiers

I'm trying to compile some function pointers assignment code.

I tried different variations of pointer assignments and __cdecl as well.

But without success, after a while I gave up... maybe you'll see something what i can not.

I compile with visual express 2008, with flags:

/Gd __cdecl calling convention

/O2 maximize speed

/TC compile all files as .c

header:

#ifdef __cplusplus
    extern "C" {
#endif

int __cdecl _intFunc(void);  // tried without __cdelc as well
int (*_get_TYPE_MODE)(void) = NULL;
...
...
#ifdef __cplusplus
    }
#endif

src:

int __cdecl _intFunc(void){return 0;}; // tried without __cdelc as well
_get_TYPE_MODE = _intFunc; // tried &_intFunc as well.

This produce following errors:

src\s.c(61) : err开发者_开发技巧or C2373: '_get_TYPE_MODE' : redefinition; different type modifiers

src\h.h(94) : see declaration of '_get_TYPE_MODE' src\s.c(61) : warning C4047: 'initializing' : 'int' differs in levels of indirection from 'int (__cdecl *)(void)'

EDIT:

When I change compiler option from /Gd to /Gz (functions as __stdcall) no issue arise in my code, but in other places code won't compile.


Don't put code in header files

header:

int (*_get_TYPE_MODE)(void);
/* without the initialization (initialization is code)
int (*_get_TYPE_MODE)(void) = NULL; */
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜