views:

47

answers:

1

Hi there,

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) : error 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.

A: 

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; */
pmg
This doesn't change anything... and I don't understand what does 'style' has to the issue ;)
bua
Apparently you have a unforgiving compiler (I don't know visual-studio-2008). Try adding `extern` to the declaration of the function pointer in the header file (and keep the `= NULL` out of there)
pmg
Eventually i've solved that with: typedef int (*_int_Function)(void); _int_Function iF = _intFuct;But every function pointer moved to the structure.good news, extern worked as well. I didn't want to use it before but don't remember why... hey, how to 'quote' aka. dim the text in the comments?
bua