首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

求解extern "C"解决思路

2012-12-29 
求解extern C本帖最后由 zyouhua83 于 2012-12-10 14:25:53 编辑#ifndef MyTest__h__#define MyTest__h_

求解extern "C"
本帖最后由 zyouhua83 于 2012-12-10 14:25:53 编辑


#ifndef MyTest__h__
#define MyTest__h__

#ifdef __cplusplus
extern "C" {                      //...........1处是否有意义
#endif

typedef struct IMyTest IMyTest;
typedef void (*_setMyTest_t)(IMyTest * nMyTest);

#ifdef __cplusplus
}
#endif
#endif // MyTest-_h__



#ifndef MyTest_h__
#define MyTest_h__

#ifdef _MSC_VER
#pragma pack(push,1)
#endif

#ifdef __cplusplus
extern "C" {                        //..........2处是否有意义
#endif

struct IMyTest
{
_setMyTest_t mSetMyTest;
void * mMyTest;
}__pack;


#ifdef __cplusplus
}
#endif

#ifdef _MSC_VER
#pragma pack(pop)
#endif
#endif // MyTest_h__


求解1和2处是否有意义
[解决办法]
引用:
typedef struct IMyTest IMyTest;
    typedef void (*_setMyTest_t)(IMyTest * nMyTest);


对类(结构)名无意义
对函数类型有意义

$7.5/1
All function types, function names with external linkage, and variable names with external linkage have a language linkage. ...




引用:
struct IMyTest
{
    _setMyTest_t mSetMyTest;
    void * mMyTest;
}__pack;


对类(结构)成员无意义

$7.5/4
... A C language linkage is ignored in determining the language linkage of the names of class
members and the function type of class member functions. 

如上都是2011标准,与2003标准一致,没有实质变化,只是表述更具体

热点排行
Bad Request.