代码之家  ›  专栏  ›  技术社区  ›  bua

函数指针错误C2373:重新定义;不同类型修饰符

  •  0
  • bua  · 技术社区  · 15 年前


    我尝试了不同的指针分配和cdecl。
    但是没有成功,过了一段时间我放弃了。。。也许你会看到一些我看不到的东西。

    我使用visual express 2008编译,带有标志:

    /Gd\uu cdecl呼叫约定

    /TC将所有文件编译为.c

    标题:

    #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.
    

    这会产生以下错误:

    src\h.h(94):参见“\u get\u TYPE\u MODE”的声明 src\s.c(61):警告C4047:'initialization':'int'与'int(\u cdecl*)(void)'的间接寻址级别不同

    编辑:
    当我将编译器选项从/Gd改为/Gz(函数为\u stdcall)时,代码中不会出现问题,但在其他地方代码不会编译。

    1 回复  |  直到 15 年前
        1
  •  0
  •   pmg    15 年前

    不要把代码放在头文件中

    标题:

    int (*_get_TYPE_MODE)(void);
    /* without the initialization (initialization is code)
    int (*_get_TYPE_MODE)(void) = NULL; */
    
    推荐文章