我在我的头文件中定义了一个结构:
#import <UIKit/UIKit.h>
typedef struct ORIGINAL_QUOTA_DATA_tag
{
byte exch;
byte complex_stat;
char contract[8];
byte status;
byte type;
}ORIGINAL_QUOTA_DATA;
@interface NetTestAppDelegate : NSObject <UIApplicationDelegate> {
CFSocketRef _socket;
CFDataRef address;
ORIGINAL_QUOTA_DATA oQuota;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;在.m文件中:
static void TCPServerConnectCallBack(CFSocketRef socket, CFSocketCallBackType type, CFDataRef address, const void *data, void *info){
memset(&oQuota, 0, sizeof(oQuota));
}但它得到了worning:

发布于 2011-10-10 18:04:59
您正在从C函数引用oQuota (它也是静态的,但这不是问题所在)。您的oQuota变量只在您的NetTestAppDelegate的Objective-C方法实现的“作用域”内
void myCFunction()
{
// oQuota cannot be referenced here.
}
@implementation NetTestAppDelegate
- (void)myObjectiveCMethod
{
// oQuota is in scope, can reference it.
}
@end但是你能做的就是把对象传递给你的回调函数:
static void TCPServerConnectCallBack(CFSocketRef socket, CFSocketCallBackType type, CFDataRef address, const void *data, void *info){
memset(
&((NetTestAppDelegate *)info)->oQuota,
0,
sizeof(((NetTestAppDelegate *)info)->oQuota)
);
// Not sure whether the sizeof works, try it.
}在你的CFSocketContext中,你需要设置:
myCFSocketContext.info = self;https://stackoverflow.com/questions/7710762
复制相似问题