读书人

求解extern quot;Cquot;解决思路

发布时间: 2012-12-29 10:28:09 作者: rapoo

求解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标准一致,没有实质变化,只是表述更具体

读书人网 >C++

热点推荐